You are here

class InfoYmlSource in PatchInfo 8.2

Gathers patch information from info.yml files.

This source plugin will read patch information from .info.yml files of themes or modules.

In the *.info.yml file of a patched theme or module, add a new list like the one shown below:

patches:
-'https://www.drupal.org/node/1739718 Issue 1739718, Patch #32';

You can add multiple entries to the list. Each entry should start with the URL of the issue or patch followed by any kind of information about the patch. The URL is optional.

You can use any URL or description, that is convenient to you.

If you are patching a submodule, you may add the patch entry to the *.info.yml file of the submodule.

Plugin annotation


@PatchInfoSource(
  id = "patchinfo_info_yml",
  label = @Translation("info.yml", context = "PatchInfoSource"),
)

Hierarchy

Expanded class hierarchy of InfoYmlSource

File

modules/patchinfo_source_info/src/Plugin/PatchInfo/Source/InfoYmlSource.php, line 36

Namespace

Drupal\patchinfo_source_info\Plugin\patchinfo\source
View source
class InfoYmlSource extends PatchInfoSourceBase {

  /**
   * {@inheritdoc}
   */
  public function getPatches(array $info, Extension $file, string $type) {
    $return = [];
    if (!in_array($type, [
      'module',
      'theme',
    ])) {
      return $return;
    }
    if (!isset($info['patches']) || !is_array($info['patches']) || count($info['patches']) < 1) {
      return $return;
    }
    foreach ($info['patches'] as $key => $info) {

      // If a colon is used in the patch description and the user didn't enclose
      // the patch entry in single quotes as shown in the README file, the entry
      // is interpreted by the YAML parser as an array in older versions of
      // Drupal. Newer versions of Drupal will fail with a YAML parser exception
      // that we can not reasonably prevent, but to prevent possible database
      // exceptions in older versions of Drupal, we replace the actual
      // information with a warning message instructing the user to check the
      // .info.yml file syntax and log the error as well.
      if (is_array($info)) {
        $this->loggerFactory
          ->get('patchinfo_source_info')
          ->warning($this
          ->t('Malformed patch entry detected in @module.info.yml at index @key. Check the syntax or your info.yml file! In most cases, this may be fixed by enclosing the patch entry in single or double quotes.', [
          '@module' => $file
            ->getName(),
          '@key' => $key,
        ]));
        $info = $this
          ->t('Malformed patch entry detected. Check the syntax of your info.yml file! In most cases, this may be fixed by enclosing the patch entry in single or double quotes.');
      }
      $return[$file
        ->getName()][] = [
        'info' => $info,
        'source' => $file
          ->getPath() . '/' . $file
          ->getName() . '.info.yml',
      ];
    }
    return $return;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
InfoYmlSource::getPatches public function Gets patch information for a module from a patch source. Overrides PatchInfoSourceBase::getPatches
PatchInfoSourceBase::$loggerFactory protected property The logger factory.
PatchInfoSourceBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create 1
PatchInfoSourceBase::getLabel public function Gets the plugin label. Overrides PatchInfoSourceInterface::getLabel
PatchInfoSourceBase::__construct public function Constructs a PatchInfoSourceBase object. Overrides PluginBase::__construct 1
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.