Returns the replacement for the relations config placeholder

@return string
506815
protected function getRelationsConfigReplace()
    {
        $relationships = $this->collectRelationshipDataForConfig();

        if ( ! count($relationships)) return '';


        $replace = $this->tab() . "protected \$relationsConfig = [\n";

        foreach ($relationships as $name => $relationship) {

            $replace .= $this->tab(2) . "'" . $name . "' => [\n";

            $rows = [];

            if (array_get($relationship, 'field')) {
                $rows['field'] = $relationship['field'];
            }

            if (array_get($relationship, 'special')) {
                $rows['type'] = $relationship['specialString'];
            } else {
                $rows['parent'] = ($relationship['reverse'] ? 'false' : 'true');
            }

            if (array_get($relationship, 'translated') === true) {
                $rows['translated'] = 'true';
            }

            $longestPropertyLength = $this->getLongestKey($rows);

            foreach ($rows as $property => $value) {

                $replace .= $this->tab(3) . "'"
                    . str_pad($property . "'", $longestPropertyLength + 1)
                    . " => {$value},\n";
            }


            $replace .= $this->tab(2) . "],\n";
        }

        $replace .= $this->tab() . "];\n\n";

        return $replace;
    }
207671
public function getDefaultElements()
    {
        $relations = $this->owner->uninherited('element_defaults');
        if (!$relations) $relations = [];

        // inherit relations from another PageType
        if ($inherit_relations_from = $this->owner->uninherited('element_relations_inherit_from'))
        {
            if ($inherit_relations = Config::inst()->get($inherit_relations_from, 'element_defaults', Config::UNINHERITED))
            {
                $relations = array_merge_recursive($relations, $inherit_relations);
            }
        }
        return $relations;
    }
825130
public function getPlaceholder(): Placeholder
    {
        if ($this->placeholderInstance === null) {
            $this->placeholderInstance = new Placeholder();
        }

        return $this->placeholderInstance;
    }
702839
public function getReplacements()
    {

        return array_merge(parent::getReplacements(), [
            'repository' => $this->getRepository(),
            'eloquent' => $this->getEloquentRepository(),
            'placeholder' => $this->bindPlaceholder,
        ]);
    }
75892
protected function replaceKeyPlaceholders()
    {
        if ( ! $this->model) {
            return $this;
        }

        $placeholder = static::MODEL_KEY_PLACEHOLDER;

        foreach ($this->rules as $key => &$ruleSet) {

            if (is_string($ruleSet)) {

                $ruleSet = str_replace($placeholder, $this->model->getKey(), $ruleSet);
                continue;
            }

            if (is_array($ruleSet)) {

                foreach ($ruleSet as &$rule) {
                    $rule = str_replace($placeholder, $this->model->getKey(), $rule);
                }

                unset($rule);
            }
        }

        unset($ruleSet);

        return $this;
    }
916167
private function getRelationships()
    {
        $r = '';

        $relationships = (array)$this->xml->xpath('/draggy/relationships/relation');

        foreach ($relationships as $relation) {
            $relationAttributes = (array)$relation;
            $relationAttributes = $relationAttributes['@attributes'];

            $this->checkMandatoryAttributes('Relationship', $relationAttributes, ['from', 'to', 'type']);

            $r .= 'var l = new Link(\'' . str_replace(
                '\\',
                '\\\\',
                $relationAttributes['from']
            ) . '\',\'' . str_replace(
                '\\',
                '\\\\',
                $relationAttributes['to']
            ) . '\',\'' . $relationAttributes['type'] . '\',' . ( isset( $relationAttributes['fromAttribute'] ) ? '\'' . $relationAttributes['fromAttribute'] . '\'' : 'undefined' ) . ', ' . ( isset( $relationAttributes['toAttribute'] ) ? '\'' . $relationAttributes['toAttribute'] . '\'' : 'undefined' ) . ')' . PHP_EOL;

            if (isset( $relationAttributes['broken'] )) {
                $r .= 'l.setBroken(' . $relationAttributes['broken'] . ');' . PHP_EOL;
            }

            if (isset( $relationAttributes['persist'] )) {
                if ('true' === $relationAttributes['persist']) { // Backwards compatibility
                    $relationAttributes['persist'] = 'both';
                }

                $r .= 'l.setPersist("' . $relationAttributes['persist'] . '");' . PHP_EOL;
            } else { // Backwards compatibility
                $r .= 'l.setPersist(true);' . PHP_EOL;
            }

            if (isset( $relationAttributes['remove'] )) {
                if ('true' === $relationAttributes['remove']) { // Backwards compatibility
                    $relationAttributes['remove'] = 'both';
                }
                $r .= 'l.setRemove("' . $relationAttributes['remove'] . '");' . PHP_EOL;
            } else { // Backwards compatibility
                $r .= 'l.setRemove(true);' . PHP_EOL;
            }
        }

        return $r;
    }
161413
public function getContent()
    {
        ksort($this->relations);

        $relations = '';

        foreach ($this->relations as $name => $relation) {
            $relations .= $relation->getContent();
        }

        return strtr($this->getStubContent('relations'), [
            '{{namespace}}' => $this->namespace,
            '{{name}}'      => $this->name,
            '{{relations}}' => $relations,
        ]);
    }
1312940
public function getDirtyRelations()
    {
        $dirtyRelations = [];
        foreach ($this->_relations as $relationName) {
            if (array_key_exists($relationName, $this->_oldRelationValue)) {
                $dirtyRelations[$relationName] = $this->owner->{$relationName};
            }
        }
        return $dirtyRelations;
    }
630262
public function getSearchFields()
    {
        $fields = parent::getSearchFields();
        $class = $this->modelClass;
        $use_autocomplete = $this->getConvertToAutocomplete();

        $db = Config::inst()->get($class, "db");
        $has_one = Config::inst()->get($class, "has_one");
        $has_many = Config::inst()->get($class, "has_many");
        $many_many = Config::inst()->get($class, "many_many");
        $belongs_many_many = Config::inst()->get($class, "belongs_many_many");
        $associations = array_merge(
            $has_one,
            $has_many,
            $many_many,
            $belongs_many_many
        );

        // Change currently scaffolded query fields to use conventional
        // field names
        /*foreach ($fields as $field) {
            $field_class = $this->modelClass;
            $name = $field->getName();
            $title = $field->Title();
            $db_field = $name;
            $in_db = false;

            // Find any text fields an replace with autocomplete fields
            if (ClassInfo::class_name($field) == TextField::class && $use_autocomplete) {
                // If this is a relation, switch class name
                if (strpos($name, "__")) {
                    $parts = explode("__", $db_field);
                    $field_class = isset($associations[$parts[0]]) ? $associations[$parts[0]] : null;
                    $db_field = $parts[1];
                    $in_db = ($field_class) ? true : false;
                }

                // If this is in the DB (not casted)
                if (in_array($db_field, array_keys($db))) {
                    $in_db = true;
                }

                if ($in_db) {
                    $fields->replaceField(
                        $name,
                        $field = AutoCompleteField::create(
                            $name,
                            $title,
                            $field->Value(),
                            $field_class,
                            $db_field
                        )->setDisplayField($db_field)
                        ->setLabelField($db_field)
                        ->setStoredField($db_field)
                    );
                }
            }

            $field->setName($name);
        }*/

        return $fields;
    }
1199174
protected function _getConfigSet() : array
    {

        if (empty($_SERVER) && empty($GLOBALS['argv'])) {
            return [];
        }

        return $this->sortConfigSet(
            $this->getConfigSet(),
            $this->get(self::HIERARCHY_PLACEHOLDER_INDEX)
        );

    }
364640
public function getConfigurationOverrides()
	{
		if ($this->overrides) {
			return $this->overrides;
		}

		return $this->overrides = $this->container['config.universal_loader']->load($this->getSupraRoot().'/config.yml'); //@todo: resolve config per environment

	}
1315407
public function searchAndReplace()
	{
		$this->search();

		$this->replacement = new Replacement($this->formatted, $this->str);

		$this->replacement->replace();
		
		return $this->replacement->getStr();
	}
894571
protected function replaceTranslationPlaceholders()
    {
        $locales     = $this->getTranslationLocales();
        $placeholder = $this->getTranslatedRulePlaceHolder();
        $processed   = [];

        // Detect and duplicate special rules for translated locales
        foreach ($this->rules as $key => $ruleSet) {

            if (false === strpos($key, $placeholder)) {
                $processed[ $key ] = $ruleSet;
                continue;
            }

            // Add the rule for each translatable locale separately
            foreach ($locales as $locale) {

                $localizedKey  = str_replace($placeholder, $locale, $key);
                $localizedRule = $ruleSet;

                // Replace placeholders for rulesets, whether they formatted as string or array
                if (is_array($localizedRule)) {

                    $localizedRule = array_map(
                        function ($part) use ($placeholder, $locale) {
                            return str_replace($placeholder, $locale, $part);
                        },
                        $localizedRule
                    );

                } else {

                    $localizedRule = str_replace($placeholder, $locale, $localizedRule);
                }

                $processed[ $localizedKey ] = $localizedRule;
            }
        }

        $this->rules = $processed;

        return $this;
    }
452557
protected function getCmsOrderedConfigReplace()
    {
        $orderColumns = $this->data['ordered_by'] ?: [];


        // for now, ignore the ordering if the column to order on is translated
        $translatedOrderColumns = array_intersect(array_keys($orderColumns
        ), $this->data['translated_attributes']);

        if (count($translatedOrderColumns)) {
            foreach ($translatedOrderColumns as $column) {
                unset($orderColumns[ $column ]);
            }
        }

        if ( ! count($orderColumns)) return '';
        

        // we only need to set a config if the scope method is global
        if (config('pxlcms.generator.models.scopes.position_order') !== CmsModelWriter::SCOPE_GLOBAL) return '';


        // align assignment signs by longest attribute
        $longestLength = 0;

        foreach ($orderColumns as $attribute => $direction) {

            if (strlen($attribute) > $longestLength) {
                $longestLength = strlen($attribute);
            }
        }

        $replace = $this->tab() . "protected \$cmsOrderBy = [\n";

        foreach ($orderColumns as $attribute => $direction) {

            $replace .= $this->tab(2)
                . "'" . str_pad($attribute . "'", $longestLength + 1)
                . " => '" . $direction . "',\n";
        }

        $replace .= $this->tab() . "];\n\n";

        return $replace;
    }
1181361
public function placeholder($config = null): string
    {
        $config = array_merge($this->defaults, $config ?? []);

        switch ($config['type']) {
            case 'svg':
                return $this->placeholderSVG($config);
            case 'gif':
                return $this->placeholderGIF($config);
            case 'silhouette':
                return $this->placeholderSilhuette($config);
        }

        return '';
    }
1353744
public function getReplacements()
    {
        $modelGenerator = new ModelGenerator([
            'name' => $this->name
        ]);
        $model = $modelGenerator->getRootNamespace() . '\\' . $modelGenerator->getName();
        $model = str_replace([
            "\\",
            '/'
        ], '\\', $model);

        return array_merge(parent::getReplacements(), [
            'model' => $model
        ]);
    }
844591
public function getSource()
    {
        $source = parent::getSource();

        if (true === $this->getDI()->get('config')->get('db.use_plural')) {
            $source = str_plural($source);
        }

        if ($prefix = $this->getDI()->get('config')->get('db.prefix')) {
            return $prefix . $source;
        }

        return $source;
    }