X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fdrupalmoduleupgrader%2Fsrc%2FPlugin%2FDMU%2FConverter%2FFunctions%2FVariableGet.php;fp=web%2Fmodules%2Fcontrib%2Fdrupalmoduleupgrader%2Fsrc%2FPlugin%2FDMU%2FConverter%2FFunctions%2FVariableGet.php;h=915edb3561f54d61c2ac35cb7cdf86be287c44a0;hp=0000000000000000000000000000000000000000;hb=8acec36f19c470dfcda1ae2336826a782f41874c;hpb=e0411c4e83ba0d079034db83c3f7f55be24a0e35 diff --git a/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/Functions/VariableGet.php b/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/Functions/VariableGet.php new file mode 100644 index 000000000..915edb356 --- /dev/null +++ b/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/Functions/VariableGet.php @@ -0,0 +1,91 @@ +tryRewrite($call, $target)) { + $arguments = $call->getArguments(); + $key = $arguments[0]->toValue(); + + if ($arguments[1] instanceof ScalarNode) { + // @TODO Couldn't convert() derive the schema from $this->defaults? + // That'd be preferable to having yet another state property ($schema) + // on this class. + $this->defaults[$key] = $arguments[1]->toValue(); + $this->schema[$key]['type'] = getType($this->defaults[$key]); + } + else { + $comment = << $target->id() ]; + $this->buildFixMe($comment, $variables)->prependTo($call->getStatement()); + } + + return ClassMethodCallNode::create('\Drupal', 'config') + ->appendArgument($target->id() . '.settings') + ->appendMethodCall('get') + ->appendArgument(clone $arguments[0]); + } + } + + /** + * {@inheritdoc} + */ + public function convert(TargetInterface $target) { + parent::convert($target); + + if ($this->defaults && $this->schema) { + $group = $target->id() . '.settings'; + + $this->write($target, InstallStorage::CONFIG_INSTALL_DIRECTORY . '/' . $group . '.yml', Yaml::encode($this->defaults)); + $this->defaults = []; + + $schema = [ + $group => [ + 'type' => 'mapping', + 'label' => (string) $this->t('Settings'), + 'mapping' => $this->schema, + ], + ]; + $this->write($target, InstallStorage::CONFIG_SCHEMA_DIRECTORY . '/' . $target->id() . '.schema.yml', Yaml::encode($schema)); + $this->schema = []; + } + } + +}