You are here

function inline_responsive_image_form_editor_image_dialog_alter in Inline responsive images 7

Same name and namespace in other branches
  1. 8 inline_responsive_image.module \inline_responsive_image_form_editor_image_dialog_alter()

File

./inline_responsive_image.module, line 18

Code

function inline_responsive_image_form_editor_image_dialog_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  $image_element = $form_state
    ->get('image_element') ?: [];
  $responsive_image_styles = entity_load_multiple('responsive_image_style');
  $image_styles = entity_load_multiple('image_style');
  foreach ($responsive_image_styles as $key => $style) {
    $styles[$key] = '[responsive]' . $style
      ->label();
  }
  foreach ($image_styles as $key => $style) {
    $styles[$key] = $style
      ->label();
  }
  $form['style'] = array(
    '#type' => 'select',
    '#title' => t('Style'),
    '#options' => $styles,
    '#empty_value' => '',
    '#default_value' => !empty($image_element['data-style']) ? $image_element['data-style'] : '',
    '#parents' => array(
      'attributes',
      'data-style',
    ),
  );
}