You are here

protected function ResponsiveTrait::createBreakpointStyleFormClassIndexBasedField in Bootstrap Styles 1.0.x

Create breakpoint field for class index based field like padding.

Parameters

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

string $field_name: The field name.

string $breakpoint_key: The breakpoint key.

string $group_id: The plugin group id.

array $storage: An associative array containing the form storage.

string $storage_key: The storage key of the field in the storage array if it's different from the field name.

1 call to ResponsiveTrait::createBreakpointStyleFormClassIndexBasedField()
ResponsiveTrait::createBreakpointsStyleFormClassIndexBasedFields in src/ResponsiveTrait.php
Create breakpoints fields for class index based field like padding.

File

src/ResponsiveTrait.php, line 253

Class

ResponsiveTrait
A Trait for responsive methods.

Namespace

Drupal\bootstrap_styles

Code

protected function createBreakpointStyleFormClassIndexBasedField(array &$form, string $field_name, string $breakpoint_key, string $group_id, array $storage, string $storage_key = NULL) {
  $breakpoint_default_value = 0;
  if (isset($storage[$field_name . '_' . $breakpoint_key]['class'])) {
    $breakpoint_default_value = $this
      ->getStyleOptionIndexByClass($field_name . '_' . $breakpoint_key, $storage[$field_name . '_' . $breakpoint_key]['class']);
  }
  $form[$field_name . '_' . $breakpoint_key] = $form[$field_name];
  $form[$field_name . '_' . $breakpoint_key]['#options'] = $this
    ->getStyleOptions($field_name . '_' . $breakpoint_key);
  $form[$field_name . '_' . $breakpoint_key]['#max'] = $this
    ->getStyleOptionsCount($field_name . '_' . $breakpoint_key);
  $form[$field_name . '_' . $breakpoint_key]['#default_value'] = $breakpoint_default_value;
  $form[$field_name . '_' . $breakpoint_key]['#validated'] = TRUE;

  // Add the breakpoints to the classes if exists.
  if (isset($form[$field_name . '_' . $breakpoint_key]['#attributes']['class'])) {
    foreach ($form[$field_name . '_' . $breakpoint_key]['#attributes']['class'] as $key => $value) {
      $form[$field_name . '_' . $breakpoint_key]['#attributes']['class'][$key] = $value . '-' . $breakpoint_key;
    }
  }
  $form[$field_name . '_' . $breakpoint_key]['#states']['visible'][':input.bs_responsive_' . $group_id]['value'] = $breakpoint_key;

  // Hide the generic one.
  $form[$field_name]['#states']['visible'][':input.bs_responsive_' . $group_id]['value'] = 'all';
}