b208d588e465b60fd82cea2b96edec6708b62cf8
[yaffs-website] / BootstrapLayouts / BootstrapLayoutsHandlerBase.php
1 <?php
2
3 namespace Drupal\bootstrap_layouts\Plugin\BootstrapLayouts;
4
5 use Drupal\bootstrap_layouts\BootstrapLayout;
6 use Drupal\Core\Plugin\PluginBase;
7 use Symfony\Component\DependencyInjection\ContainerAwareTrait;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
9
10 /**
11  * Class BootstrapLayoutsHandlerBase
12  */
13 abstract class BootstrapLayoutsHandlerBase extends PluginBase implements BootstrapLayoutsHandlerInterface {
14
15   use ContainerAwareTrait;
16
17   /**
18    * {@inheritdoc}
19    */
20   public function __construct(array $configuration, $plugin_id, $plugin_definition, ContainerInterface $container = NULL) {
21     parent::__construct($configuration, $plugin_id, $plugin_definition);
22     if (!isset($container)) {
23       $container = \Drupal::getContainer();
24     }
25     $this->setContainer($container);
26   }
27
28   /**
29    * {@inheritdoc}
30    */
31   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
32     return new static($configuration, $plugin_id, $plugin_definition, $container);
33   }
34
35   /**
36    * {@inheritdoc}
37    */
38   public function getLabel() {
39     return isset($this->pluginDefinition['label']) ? $this->pluginDefinition['label'] : $this->getPluginId();
40   }
41
42   /**
43    * {@inheritdoc}
44    */
45   public function loadInstance($entity_id) {
46     $layouts = $this->loadInstances([$entity_id]);
47     return reset($layouts);
48   }
49
50   /**
51    * {@inheritdoc}
52    */
53   public function saveInstance($entity_id, BootstrapLayout $layout) {
54     $this->saveInstances([$entity_id => $layout]);
55   }
56
57 }