You are here

public function SettingBase::getSettingElement in Express 8

Retrieves the form element for the setting.

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.

Return value

\Drupal\bootstrap\Utility\Element The setting element object.

Overrides SettingInterface::getSettingElement

11 calls to SettingBase::getSettingElement()
BreadcrumbHome::alterFormElement in themes/contrib/bootstrap/src/Plugin/Setting/Components/Breadcrumbs/BreadcrumbHome.php
The alter method to store the code.
BreadcrumbTitle::alterFormElement in themes/contrib/bootstrap/src/Plugin/Setting/Components/Breadcrumbs/BreadcrumbTitle.php
The alter method to store the code.
CdnJsdelivrTheme::alterFormElement in themes/contrib/bootstrap/src/Plugin/Setting/Advanced/Cdn/CdnJsdelivrTheme.php
The alter method to store the code.
CdnJsdelivrVersion::alterFormElement in themes/contrib/bootstrap/src/Plugin/Setting/Advanced/Cdn/CdnJsdelivrVersion.php
The alter method to store the code.
CdnProvider::alterFormElement in themes/contrib/bootstrap/src/Plugin/Setting/Advanced/Cdn/CdnProvider.php
The alter method to store the code.

... See full list

File

themes/contrib/bootstrap/src/Plugin/Setting/SettingBase.php, line 142
Contains \Drupal\bootstrap\Plugin\Setting\SettingBase.

Class

SettingBase
Base class for a setting.

Namespace

Drupal\bootstrap\Plugin\Setting

Code

public function getSettingElement(Element $form, FormStateInterface $form_state) {

  // Construct the group elements.
  $group = $this
    ->getGroupElement($form, $form_state);
  $plugin_id = $this
    ->getPluginId();
  if (!isset($group->{$plugin_id})) {

    // Set properties from the plugin definition.
    foreach ($this
      ->getElementProperties() as $name => $value) {
      $group->{$plugin_id}
        ->setProperty($name, $value);
    }

    // Set default value from the stored form state value or theme setting.
    $default_value = $form_state
      ->getValue($plugin_id, $this->theme
      ->getSetting($plugin_id));
    $group->{$plugin_id}
      ->setProperty('default_value', $default_value);

    // Append additional "see" link references to the description.
    $description = (string) $group->{$plugin_id}
      ->getProperty('description') ?: '';
    $links = [];
    foreach ($this->pluginDefinition['see'] as $url => $title) {
      $link = Element::createStandalone([
        '#type' => 'link',
        '#url' => Url::fromUri($url),
        '#title' => $title,
        '#attributes' => [
          'target' => '_blank',
        ],
      ]);
      $links[] = (string) $link
        ->renderPlain();
    }
    if (!empty($links)) {
      $description .= '<br>';
      $description .= t('See also:');
      $description .= ' ' . implode(', ', $links);
      $group->{$plugin_id}
        ->setProperty('description', $description);
    }
  }
  return $group->{$plugin_id};
}