You are here

public function LayoutPluginManager::processDefinition in Layout Plugin (obsolete, use core's Layout Discovery) 8

Performs extra processing on plugin definitions.

By default we add defaults for the type to the definition. If a type has additional processing logic they can do that by replacing or extending the method.

Overrides DefaultPluginManager::processDefinition

File

src/Plugin/Layout/LayoutPluginManager.php, line 68

Class

LayoutPluginManager
Plugin type manager for all layouts.

Namespace

Drupal\layout_plugin\Plugin\Layout

Code

public function processDefinition(&$definition, $plugin_id) {
  parent::processDefinition($definition, $plugin_id);

  // Add the module or theme path to the 'path'.
  if ($this->moduleHandler
    ->moduleExists($definition['provider'])) {
    $definition['provider_type'] = 'module';
    $base_path = $this->moduleHandler
      ->getModule($definition['provider'])
      ->getPath();
  }
  elseif ($this->themeHandler
    ->themeExists($definition['provider'])) {
    $definition['provider_type'] = 'theme';
    $base_path = $this->themeHandler
      ->getTheme($definition['provider'])
      ->getPath();
  }
  else {
    $base_path = '';
  }
  $definition['path'] = !empty($definition['path']) ? $base_path . '/' . $definition['path'] : $base_path;

  // Add a dependency on the provider of the library.
  if (!empty($definition['library'])) {
    list($library_provider, ) = explode('/', $definition['library']);
    if ($this->moduleHandler
      ->moduleExists($library_provider)) {
      $definition['dependencies'] = [
        'module' => [
          $library_provider,
        ],
      ];
    }
    elseif ($this->themeHandler
      ->themeExists($library_provider)) {
      $definition['dependencies'] = [
        'theme' => [
          $library_provider,
        ],
      ];
    }
  }

  // Add the path to the icon filename.
  if (!empty($definition['icon'])) {
    $definition['icon'] = $definition['path'] . '/' . $definition['icon'];
  }

  // If 'template' is set, then we'll derive 'template_path' and 'theme'.
  if (!empty($definition['template'])) {
    $template_parts = explode('/', $definition['template']);
    $definition['template'] = array_pop($template_parts);
    $definition['theme'] = strtr($definition['template'], '-', '_');
    $definition['template_path'] = $definition['path'];
    if (count($template_parts) > 0) {
      $definition['template_path'] .= '/' . implode('/', $template_parts);
    }
  }

  // If 'css' is set, then we'll derive 'library'.
  if (!empty($definition['css'])) {
    $definition['css'] = $definition['path'] . '/' . $definition['css'];
    $definition['library'] = 'layout_plugin/' . $plugin_id;
  }

  // Generate the 'region_names' key from the 'regions' key.
  $definition['region_names'] = array();
  if (!empty($definition['regions']) && is_array($definition['regions'])) {
    foreach ($definition['regions'] as $region_id => $region_definition) {
      $definition['region_names'][$region_id] = $region_definition['label'];
    }
  }
}