LinkAttributesManager.php in Link Attributes widget 8
File
src/LinkAttributesManager.php
View source
<?php
namespace Drupal\link_attributes;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Plugin\Discovery\ContainerDerivativeDiscoveryDecorator;
use Drupal\Core\Plugin\Discovery\YamlDiscovery;
class LinkAttributesManager extends DefaultPluginManager implements PluginManagerInterface {
protected $defaults = [
'title' => '',
'type' => '',
'description' => '',
];
public function __construct(ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend) {
$this
->alterInfo('link_attributes_plugin');
$this->moduleHandler = $module_handler;
$this
->setCacheBackend($cache_backend, 'link_attributes', [
'link_attributes',
]);
}
protected function getDiscovery() {
if (!isset($this->discovery)) {
$this->discovery = new YamlDiscovery('link_attributes', $this->moduleHandler
->getModuleDirectories());
$this->discovery
->addTranslatableProperty('title');
$this->discovery = new ContainerDerivativeDiscoveryDecorator($this->discovery);
}
return $this->discovery;
}
public function processDefinition(&$definition, $plugin_id) {
parent::processDefinition($definition, $plugin_id);
if (empty($definition['type'])) {
$definition['type'] = 'textfield';
}
}
}