3 namespace Drupal\paragraphs\Entity;
5 use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
6 use Drupal\Core\Entity\EntityWithPluginCollectionInterface;
7 use Drupal\paragraphs\ParagraphsBehaviorCollection;
8 use Drupal\paragraphs\ParagraphsBehaviorInterface;
9 use Drupal\paragraphs\ParagraphsTypeInterface;
12 * Defines the ParagraphsType entity.
15 * id = "paragraphs_type",
16 * label = @Translation("Paragraphs type"),
18 * "list_builder" = "Drupal\paragraphs\Controller\ParagraphsTypeListBuilder",
20 * "add" = "Drupal\paragraphs\Form\ParagraphsTypeForm",
21 * "edit" = "Drupal\paragraphs\Form\ParagraphsTypeForm",
22 * "delete" = "Drupal\paragraphs\Form\ParagraphsTypeDeleteConfirm"
25 * config_prefix = "paragraphs_type",
26 * admin_permission = "administer paragraphs types",
36 * bundle_of = "paragraph",
38 * "edit-form" = "/admin/structure/paragraphs_type/{paragraphs_type}",
39 * "delete-form" = "/admin/structure/paragraphs_type/{paragraphs_type}/delete",
40 * "collection" = "/admin/structure/paragraphs_type",
44 class ParagraphsType extends ConfigEntityBundleBase implements ParagraphsTypeInterface, EntityWithPluginCollectionInterface {
47 * The ParagraphsType ID.
54 * The ParagraphsType label.
61 * The paragraphs type behavior plugins configuration keyed by their id.
65 public $behavior_plugins = [];
68 * Holds the collection of behavior plugins that are attached to this
71 * @var \Drupal\paragraphs\ParagraphsBehaviorCollection
73 protected $behaviorCollection;
78 public function getBehaviorPlugins() {
79 if (!isset($this->behaviorCollection)) {
80 $this->behaviorCollection = new ParagraphsBehaviorCollection(\Drupal::service('plugin.manager.paragraphs.behavior'), $this->behavior_plugins);
82 return $this->behaviorCollection;
88 public function getBehaviorPlugin($instance_id) {
89 return $this->getBehaviorPlugins()->get($instance_id);
95 public function getEnabledBehaviorPlugins() {
96 return $this->getBehaviorPlugins()->getEnabled();
102 public function getPluginCollections() {
103 return ['behavior_plugins' => $this->getBehaviorPlugins()];
109 public function hasEnabledBehaviorPlugin($plugin_id) {
110 $plugins = $this->getBehaviorPlugins();
111 if ($plugins->has($plugin_id)) {
112 /** @var ParagraphsBehaviorInterface $plugin */
113 $plugin = $plugins->get($plugin_id);
114 $config = $plugin->getConfiguration();
115 return (array_key_exists('enabled', $config) && $config['enabled'] === TRUE);