You are here

public function Schemas::alterFormElement in Express 8

The alter method to store the code.

Parameters

\Drupal\bootstrap\Utility\Element $form: The Element object that comprises the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

string $form_id: String representing the name of the form itself. Typically this is the name of the function that generated the form.

Overrides SettingBase::alterFormElement

File

themes/contrib/bootstrap/src/Plugin/Setting/Schemas.php, line 34
Contains \Drupal\bootstrap\Plugin\Setting\Schemas.

Class

Schemas
The "schemas" theme setting.

Namespace

Drupal\bootstrap\Plugin\Setting

Code

public function alterFormElement(Element $form, FormStateInterface $form_state, $form_id = NULL) {
  parent::alterFormElement($form, $form_state, $form_id);
  $updates = [];
  foreach ($this->theme
    ->getPendingUpdates() as $version => $update) {
    $row = [];
    $row[] = $update
      ->getSchema();
    $row[] = new FormattableMarkup('<strong>@title</strong><p class="help-block">@description</p>', [
      '@title' => $update
        ->getLabel(),
      '@description' => $update
        ->getDescription(),
    ]);
    $row[] = $update
      ->getTheme()
      ->getTitle();
    $updates[] = [
      'class' => [
        $update
          ->getSeverity() ?: 'default',
      ],
      'data' => $row,
    ];
  }
  $form['update'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Theme Updates'),
    '#panel_type' => !!$updates ? 'primary' : 'default',
    '#open' => !!$updates,
    '#weight' => -20,
  ];
  $form['update']['table'] = [
    '#type' => 'table',
    '#header' => [
      t('Schema'),
      t('Description'),
      t('Provider'),
    ],
    '#empty' => t('There are currently no pending updates for this theme.'),
    '#rows' => $updates,
  ];
  if ($updates) {
    $form['update']['actions'] = [
      '#type' => 'actions',
    ];
    $form['update']['actions']['update'] = [
      '#type' => 'submit',
      '#value' => t('Update theme'),
      '#icon' => Bootstrap::glyphicon('open'),
      // @todo Setting a class like this is undesirable, create a suggestion.
      '#attributes' => [
        'class' => [
          'btn-primary',
        ],
      ],
      '#submit' => [
        [
          get_class($this),
          'updateTheme',
        ],
      ],
    ];
  }
}