Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function getAttributes() {
   if (!$this->attributeCollection) {
     $this->attributeCollection = new AttributeCollection($this->getAttributeManager(), $this->attributes);
     $this->attributeCollection->sort();
   }
   return $this->attributeCollection;
 }
Exemplo n.º 2
0
  /**
   * Adds the attributes enabled on the current profile.
   *
   * @param array $form
   *   An associative array containing the structure of the form.
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The current state of the form.
   * @param AttributeCollection $attributes
   *   A collection of attributes for the current profile.
   */
  private function addAttributes(array &$form, FormStateInterface &$form_state, AttributeCollection $attributes) {
    if ($attributes->count()) {
      $form['linkit_attributes'] = [
        '#type' => 'container',
        '#title' => $this->t('Attributes'),
        '#weight' => '10',
      ];

      /** @var \Drupal\linkit\AttributeInterface $plugin */
      foreach ($attributes as $plugin) {
        $plugin_name = $plugin->getHtmlName();
        $default_value = isset($input[$plugin_name]) ? $input[$plugin_name] : '';
        $form['linkit_attributes'][$plugin_name] = $plugin->buildFormElement($default_value);
        $form['linkit_attributes'][$plugin_name] += [
          '#parents' => [
            'attributes', $plugin_name,
          ],
        ];
      }
    }
  }