Pathologic was missing because of a .git folder inside.
[yaffs-website] / web / modules / contrib / paragraphs / src / ParagraphsBehaviorBase.php
1 <?php
2
3 namespace Drupal\paragraphs;
4
5 use Drupal\Component\Plugin\PluginBase;
6 use Drupal\Core\Entity\EntityFieldManager;
7 use Drupal\Core\Field\FieldConfigInterface;
8 use Drupal\Core\Form\FormStateInterface;
9 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
10 use Drupal\Core\StringTranslation\StringTranslationTrait;
11 use Drupal\paragraphs\Entity\Paragraph;
12 use Drupal\paragraphs\Entity\ParagraphsType;
13 use Symfony\Component\DependencyInjection\ContainerInterface;
14
15 abstract class ParagraphsBehaviorBase extends PluginBase implements ParagraphsBehaviorInterface, ContainerFactoryPluginInterface {
16
17   use StringTranslationTrait;
18
19   /**
20    * The entity field manager.
21    *
22    * @var \Drupal\Core\Entity\EntityFieldManagerInterface
23    */
24   protected $entityFieldManager;
25
26   /**
27    * Constructs a ParagraphsBehaviorBase object.
28    *
29    * @param array $configuration
30    *   A configuration array containing information about the plugin instance.
31    * @param string $plugin_id
32    *   The plugin_id for the plugin instance.
33    * @param mixed $plugin_definition
34    *   The plugin implementation definition.
35    * @param \Drupal\Core\Entity\EntityFieldManager $entity_field_manager
36    *   The entity field manager.
37    */
38   public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityFieldManager $entity_field_manager) {
39     parent::__construct($configuration, $plugin_id, $plugin_definition);
40     $this->configuration += $this->defaultConfiguration();
41     $this->entityFieldManager = $entity_field_manager;
42   }
43
44   /**
45    * {@inheritdoc}
46    */
47   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
48     return new static($configuration, $plugin_id, $plugin_definition,
49       $container->get('entity_field.manager')
50     );
51   }
52
53   /**
54    * {@inheritdoc}
55    */
56   public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
57     return $form;
58   }
59
60   /**
61    * {@inheritdoc}
62    */
63   public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { }
64
65   /**
66    * {@inheritdoc}
67    */
68   public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { }
69
70   /**
71    * {@inheritdoc}
72    */
73   public function defaultConfiguration() {
74     return [];
75   }
76
77   /**
78    * {@inheritdoc}
79    */
80   public function getConfiguration() {
81     return $this->configuration;
82   }
83
84   /**
85    * {@inheritdoc}
86    */
87   public function setConfiguration(array $configuration) {
88     $this->configuration = $configuration + $this->defaultConfiguration();
89   }
90
91   /**
92    * {@inheritdoc}
93    */
94   public function calculateDependencies() {
95     return [];
96   }
97
98   /**
99    * {@inheritdoc}
100    */
101   public function preprocess(&$variables) { }
102
103   /**
104    * {@inheritdoc}
105    */
106   public static function isApplicable(ParagraphsType $paragraphs_type) {
107     return TRUE;
108   }
109
110   /**
111    * {@inheritdoc}
112    */
113   public function settingsSummary(Paragraph $paragraph) {
114     return [];
115   }
116
117   /**
118    * {@inheritdoc}
119    */
120   public function buildBehaviorForm(ParagraphInterface $paragraph, array &$form, FormStateInterface $form_state) {
121     return [];
122   }
123
124   /**
125    * {@inheritdoc}
126    */
127   public function validateBehaviorForm(ParagraphInterface $paragraph, array &$form, FormStateInterface $form_state) {}
128
129   /**
130    * {@inheritdoc}
131    */
132   public function submitBehaviorForm(ParagraphInterface $paragraph, array &$form, FormStateInterface $form_state) {
133     $paragraph->setBehaviorSettings($this->getPluginId(), $form_state->getValues());
134   }
135
136   /**
137    * {@inheritdoc}
138    */
139   public function getFieldNameOptions(ParagraphsType $paragraphs_type, $field_type = NULL) {
140     $fields = [];
141     $field_definitions = $this->entityFieldManager->getFieldDefinitions('paragraph', $paragraphs_type->id());
142     foreach ($field_definitions as $name => $definition) {
143       if ($field_definitions[$name] instanceof FieldConfigInterface) {
144         if (empty($field_type) || $definition->getType() == $field_type) {
145           $fields[$name] = $definition->getLabel();
146         }
147       }
148     }
149     return $fields;
150   }
151
152 }