You are here

private function AddForm::buildRows in Linkit 8.4

Same name in this branch
  1. 8.4 src/Form/Attribute/AddForm.php \Drupal\linkit\Form\Attribute\AddForm::buildRows()
  2. 8.4 src/Form/Matcher/AddForm.php \Drupal\linkit\Form\Matcher\AddForm::buildRows()

Builds the table rows.

Only attributes that is not already applied to the profile are shown.

Return value

array An array of table rows.

1 call to AddForm::buildRows()
AddForm::buildForm in src/Form/Attribute/AddForm.php
Form constructor.

File

src/Form/Attribute/AddForm.php, line 143
Contains \Drupal\linkit\Form\Attribute\AddForm.

Class

AddForm
Provides a form to apply attributes to a profile.

Namespace

Drupal\linkit\Form\Attribute

Code

private function buildRows() {
  $rows = [];
  $applied_plugins = $this->linkitProfile
    ->getAttributes()
    ->getConfiguration();
  $all_plugins = $this->manager
    ->getDefinitions();
  uasort($all_plugins, function ($a, $b) {
    return strnatcasecmp($a['label'], $b['label']);
  });
  foreach (array_diff_key($all_plugins, $applied_plugins) as $definition) {

    /** @var \Drupal\linkit\AttributeInterface $plugin */
    $plugin = $this->manager
      ->createInstance($definition['id']);
    $row = [
      'label' => (string) $plugin
        ->getLabel(),
      'description' => (string) $plugin
        ->getDescription(),
    ];
    $rows[$plugin
      ->getPluginId()] = $row;
  }
  return $rows;
}