You are here

class VueBlockDeriver in Decoupled Blocks: Vue.js 8

Derives block plugin definitions for Vue components.

Hierarchy

Expanded class hierarchy of VueBlockDeriver

1 file declares its use of VueBlockDeriver
VueBlockDeriverTest.php in tests/src/Unit/Plugin/Derivative/VueBlockDeriverTest.php

File

src/Plugin/Derivative/VueBlockDeriver.php, line 13

Namespace

Drupal\pdb_vue\Plugin\Derivative
View source
class VueBlockDeriver extends PdbBlockDeriver {

  /**
   * Config Factory service.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * VueBlockDeriver constructor.
   *
   * @param \Drupal\pdb\ComponentDiscoveryInterface $component_discovery
   *   The component discovery service.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   Config Factory service.
   */
  public function __construct(ComponentDiscoveryInterface $component_discovery, ConfigFactoryInterface $config_factory) {
    parent::__construct($component_discovery);
    $this->configFactory = $config_factory;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static($container
      ->get('pdb.component_discovery'), $container
      ->get('config.factory'));
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $definitions = parent::getDerivativeDefinitions($base_plugin_definition);

    // Remove any demo components if development mode is not enabled.
    $config_settings = $this->configFactory
      ->get('pdb_vue.settings');
    if (isset($config_settings) && !$config_settings
      ->get('development_mode')) {
      $demos = [
        'ng2_example_1',
        'ng2_example_2',
        'ng2_example_configuration',
        'ng2_example_node',
        'ng2_hero',
        'ng2_todo',
        'react_example_1',
        'react_todo',
        'vue_example_1',
        'vue_example_2',
        'vue_example_webpack',
        'vue_spa_component',
        'vue_todo',
        'vue3_example_1',
        'vue3_spa_component',
      ];
      foreach ($definitions as $key => $definition) {
        if (in_array($key, $demos)) {
          unset($definitions[$key]);
        }
      }
    }
    return array_filter($definitions, function (array $definition) {
      return $definition['info']['presentation'] == 'vue';
    });
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
PdbBlockDeriver::$componentDiscovery protected property The component discovery service.
PdbBlockDeriver::createContexts protected function Creates the context definitions required by a block plugin.
VueBlockDeriver::$configFactory protected property Config Factory service.
VueBlockDeriver::create public static function Creates a new class instance. Overrides PdbBlockDeriver::create
VueBlockDeriver::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides PdbBlockDeriver::getDerivativeDefinitions
VueBlockDeriver::__construct public function VueBlockDeriver constructor. Overrides PdbBlockDeriver::__construct