You are here

public function AddContentMenu::buildSettingsForm in Dashboards with Layout Builder 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/Dashboard/AddContentMenu.php \Drupal\dashboards\Plugin\Dashboard\AddContentMenu::buildSettingsForm()

Build render array.

Parameters

array $form: Default form.

\Drupal\Core\Form\FormStateInterface $form_state: Default form.

array $configuration: Configuration.

Return value

array Return form array.

Overrides DashboardBase::buildSettingsForm

File

src/Plugin/Dashboard/AddContentMenu.php, line 102

Class

AddContentMenu
Show account info.

Namespace

Drupal\dashboards\Plugin\Dashboard

Code

public function buildSettingsForm(array $form, FormStateInterface $form_state, array $configuration) : array {
  $group_class = 'group-order-weight';
  $info = $this->bundleInfo
    ->getBundleInfo('node');
  $form['items'] = [
    '#type' => 'table',
    '#caption' => $this
      ->t('Menü items'),
    '#header' => [
      $this
        ->t('Label'),
      $this
        ->t('Weight'),
    ],
    '#empty' => $this
      ->t('No items.'),
    '#tableselect' => FALSE,
    '#tabledrag' => [
      [
        'action' => 'order',
        'relationship' => 'sibling',
        'group' => $group_class,
      ],
    ],
  ];
  foreach ($info as $key => $value) {
    $form['items'][$key]['#attributes']['class'][] = 'draggable';
    $form['items'][$key]['#weight'] = !isset($value['weight']) ? 0 : $value['weight'];

    // Label col.
    $form['items'][$key]['label'] = [
      '#plain_text' => $value['label'],
    ];

    // Weight col.
    $form['items'][$key]['weight'] = [
      '#type' => 'weight',
      '#title' => $this
        ->t('Weight for @title', [
        '@title' => $value['label'],
      ]),
      '#title_display' => 'invisible',
      '#default_value' => !isset($value['weight']) ? 0 : $value['weight'],
      '#attributes' => [
        'class' => [
          $group_class,
        ],
      ],
    ];
  }
  return $form;
}