You are here

public function SettingsForm::buildForm in Bootstrap Layout Builder 1.x

Same name and namespace in other branches
  1. 2.x src/Form/SettingsForm.php \Drupal\bootstrap_layout_builder\Form\SettingsForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

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

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/SettingsForm.php, line 81

Class

SettingsForm
Configure Bootstrap Layout Builder settings.

Namespace

Drupal\bootstrap_layout_builder\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config(static::SETTINGS);
  $form['hide_section_settings'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Hide "Advanced Settings"'),
    '#description' => $this
      ->t('<img src="/' . drupal_get_path('module', 'bootstrap_layout_builder') . '/images/drupal-ui/toggle-advanced-settings.png" alt="Toggle Advanced Settings Tab Visibility" title="Toggle Advanced Settings Tab Visibility">'),
    '#default_value' => $config
      ->get('hide_section_settings'),
  ];

  // Background image media bundle.
  $media_bundles = [];
  $media_bundles_info = $this->entityTypeBundleInfo
    ->getBundleInfo('media');

  // Ignore if match any of the following names.
  $disabled_bundles = [
    'audio',
    'audio_file',
    'instagram',
    'tweet',
    'document',
    'remote_video',
  ];
  foreach ($media_bundles_info as $key => $bundle) {
    if (!in_array($key, $disabled_bundles)) {
      $media_bundles[$key] = $bundle['label'] . ' (' . $key . ')';
    }
  }
  $form['background_image_bundle'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Image background media bundle'),
    '#options' => $media_bundles,
    '#description' => $this
      ->t('Image background media entity bundle.'),
    '#default_value' => $config
      ->get('background_image.bundle'),
    '#ajax' => [
      'callback' => [
        $this,
        'getFields',
      ],
      'event' => 'change',
      'method' => 'html',
      'wrapper' => 'media_image_bundle_fields',
      'progress' => [
        'type' => 'throbber',
        'message' => NULL,
      ],
    ],
  ];
  $form['background_image_field'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Image background media field'),
    '#options' => $this
      ->getFieldsByBundle($config
      ->get('background_image.bundle')),
    '#description' => $this
      ->t('Image background media entity field.'),
    '#default_value' => $config
      ->get('background_image.field'),
    '#attributes' => [
      'id' => 'media_image_bundle_fields',
    ],
    '#validated' => TRUE,
  ];
  $form['background_local_video_bundle'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Local video background media bundle'),
    '#options' => $media_bundles,
    '#description' => $this
      ->t('Background for local video media entity bundle.'),
    '#default_value' => $config
      ->get('background_local_video.bundle'),
    '#ajax' => [
      'callback' => [
        $this,
        'getFields',
      ],
      'event' => 'change',
      'method' => 'html',
      'wrapper' => 'media_local_video_bundle_fields',
      'progress' => [
        'type' => 'throbber',
        'message' => NULL,
      ],
    ],
  ];
  $form['background_local_video_field'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Local video background media field'),
    '#options' => $this
      ->getFieldsByBundle($config
      ->get('background_local_video.bundle')),
    '#description' => $this
      ->t('Local video background media entity field.'),
    '#default_value' => $config
      ->get('background_local_video.field'),
    '#attributes' => [
      'id' => 'media_local_video_bundle_fields',
    ],
    '#validated' => TRUE,
  ];
  $form['style'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Style'),
    '#open' => TRUE,
  ];
  $form['style']['background_colors'] = [
    '#type' => 'textarea',
    '#default_value' => $config
      ->get('background_colors'),
    '#title' => $this
      ->t('Background colors (classes)'),
    '#description' => $this
      ->t('<p>Enter one value per line, in the format <b>key|label</b> where <em>key</em> is the CSS class name (without the .), and <em>label</em> is the human readable name of the background.</p>'),
    '#cols' => 60,
    '#rows' => 5,
  ];
  return parent::buildForm($form, $form_state);
}