page_layouts-1.0.1/src/LayoutsPluginManager.php

src/LayoutsPluginManager.php
<?php

declare(strict_types=1);

namespace Drupal\page_layouts;

use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\page_layouts\Annotation\Layouts;

/**
 * Layouts plugin manager.
 */
final class LayoutsPluginManager extends DefaultPluginManager {

  /**
   * Constructs the object.
   */
  public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
    parent::__construct('Plugin/Layouts', $namespaces, $module_handler, LayoutsInterface::class, Layouts::class);
    $this->alterInfo('layouts_info');
    $this->setCacheBackend($cache_backend, 'layouts_plugins');
  }

  /**
   * {@inheritdoc}
   */
  public function processDefinition(&$definition, $plugin_id) {
    parent::processDefinition($definition, $plugin_id);

    foreach (['id', 'label'] as $required_property) {
      if (empty($definition[$required_property])) {
        throw new PluginException(sprintf('The layout %s must define the %s property.', $plugin_id, $required_property));
      }
    }
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc