5 * Contains \Drupal\linkit\Entity\Profile.
8 namespace Drupal\linkit\Entity;
10 use Drupal\Core\Config\Entity\ConfigEntityBase;
11 use Drupal\Core\Entity\EntityWithPluginCollectionInterface;
12 use Drupal\linkit\AttributeCollection;
13 use Drupal\linkit\MatcherCollection;
14 use Drupal\linkit\MatcherInterface;
15 use Drupal\linkit\ProfileInterface;
18 * Defines the linkit profile entity.
21 * id = "linkit_profile",
22 * label = @Translation("Linkit profile"),
24 * "list_builder" = "Drupal\linkit\ProfileListBuilder",
26 * "add" = "Drupal\linkit\Form\Profile\AddForm",
27 * "edit" = "Drupal\linkit\Form\Profile\EditForm",
28 * "delete" = "Drupal\Core\Entity\EntityDeleteForm"
31 * admin_permission = "administer linkit profiles",
32 * config_prefix = "linkit_profile",
38 * "collection" = "/admin/config/content/linkit",
39 * "edit-form" = "/admin/config/content/linkit/manage/{linkit_profile}",
40 * "delete-form" = "/admin/config/content/linkit/manage/{linkit_profile}/delete"
51 class Profile extends ConfigEntityBase implements ProfileInterface, EntityWithPluginCollectionInterface {
54 * The ID of this profile.
61 * The human-readable label of this profile.
68 * Description of this profile.
72 protected $description;
75 * Configured attribute for this profile.
77 * An associative array of attribute assigned to the profile, keyed by the
78 * attribute id of each attribute and using the properties:
79 * - id: The plugin ID of the attribute instance.
80 * - status: (optional) A Boolean indicating whether the attribute is enabled
81 * in the profile. Defaults to FALSE.
82 * - weight: (optional) The weight of the attribute in the profile.
87 protected $attributes = [];
90 * Holds the collection of attributes that are attached to this profile.
92 * @var \Drupal\linkit\AttributeCollection
94 protected $attributeCollection;
97 * Configured matchers for this profile.
99 * An associative array of matchers assigned to the profile, keyed by the
100 * matcher ID of each matcher and using the properties:
101 * - id: The plugin ID of the matchers instance.
102 * - status: (optional) A Boolean indicating whether the matchers is enabled
103 * in the profile. Defaults to FALSE.
104 * - weight: (optional) The weight of the matchers in the profile.
109 protected $matchers = [];
112 * Holds the collection of matchers that are attached to this profile.
114 * @var \Drupal\linkit\MatcherCollection
116 protected $matcherCollection;
121 public function getDescription() {
122 return $this->get('description');
128 public function setDescription($description) {
129 $this->set('description', trim($description));
136 public function getAttribute($attribute_id) {
137 return $this->getAttributes()->get($attribute_id);
143 public function getAttributes() {
144 if (!$this->attributeCollection) {
145 $this->attributeCollection = new AttributeCollection($this->getAttributeManager(), $this->attributes);
146 $this->attributeCollection->sort();
148 return $this->attributeCollection;
154 public function addAttribute(array $configuration) {
155 $this->getAttributes()->addInstanceId($configuration['id'], $configuration);
156 return $configuration['id'];
162 public function removeAttribute($attribute_id) {
163 unset($this->attributes[$attribute_id]);
164 $this->getAttributes()->removeInstanceId($attribute_id);
171 public function setAttributeConfig($attribute_id, array $configuration) {
172 $this->attributes[$attribute_id] = $configuration;
173 $this->getAttributes()->setInstanceConfiguration($attribute_id, $configuration);
180 public function getMatcher($instance_id) {
181 return $this->getMatchers()->get($instance_id);
187 public function getMatchers() {
188 if (!$this->matcherCollection) {
189 $this->matcherCollection = new MatcherCollection($this->getMatcherManager(), $this->matchers);
190 $this->matcherCollection->sort();
192 return $this->matcherCollection;
198 public function addMatcher(array $configuration) {
199 $configuration['uuid'] = $this->uuidGenerator()->generate();
200 $this->getMatchers()->addInstanceId($configuration['uuid'], $configuration);
201 return $configuration['uuid'];
207 public function removeMatcher(MatcherInterface $matcher) {
208 $this->getMatchers()->removeInstanceId($matcher->getUuid());
216 public function setMatcherConfig($instance_id, array $configuration) {
217 $this->matchers[$instance_id] = $configuration;
218 $this->getMatchers()->setInstanceConfiguration($instance_id, $configuration);
225 public function getPluginCollections() {
227 'attributes' => $this->getAttributes(),
228 'matchers' => $this->getMatchers(),
233 * Returns the attribute manager.
235 * @return \Drupal\Component\Plugin\PluginManagerInterface
236 * The attribute manager.
238 protected function getAttributeManager() {
239 return \Drupal::service('plugin.manager.linkit.attribute');
243 * Returns the matcher manager.
245 * @return \Drupal\Component\Plugin\PluginManagerInterface
246 * The matcher manager.
248 protected function getMatcherManager() {
249 return \Drupal::service('plugin.manager.linkit.matcher');