You are here

function _insert_settings_form in Insert 8.2

Parameters

array $settings:

string $insertType:

Return value

array

1 call to _insert_settings_form()
insert_field_widget_third_party_settings_form in ./insert.module
Implements hook_field_widget_third_party_settings_form().

File

./insert.module, line 592

Code

function _insert_settings_form(array $settings, $insertType) {
  $stylesLists = [
    INSERT_TYPE_FILE => InsertUtility::aggregateStyles(INSERT_TYPE_FILE),
    INSERT_TYPE_IMAGE => InsertUtility::aggregateStyles(INSERT_TYPE_IMAGE),
  ];
  if (!isset($stylesLists[$insertType]) || count($stylesLists[$insertType]) === 0) {
    return [];
  }
  $stylesList = InsertUtility::stylesListToOptions($stylesLists[$insertType]);
  $element = [
    '#type' => 'details',
    '#title' => t('Insert'),
    '#weight' => 20,
  ];
  $element['styles_heading'] = [
    '#type' => 'markup',
    '#markup' => t('Select which styles should be available for inserting images into text areas. If no styles are selected, the option to use a style is not displayed; If only one style is selected, that one is used automatically when inserting. If all styles are selected, new styles will be enabled by default.'),
    '#weight' => 21,
  ];
  $element['styles'] = [
    '#type' => 'table',
    '#default_value' => !empty($settings['styles']['<all>']) ? array_keys($stylesList) : $settings['styles'],
    '#element_validate' => [
      [
        InsertUtility::class,
        'validateList',
      ],
    ],
    '#weight' => 22,
    '#tableselect' => TRUE,
    '#header' => [
      t('Select all'),
    ],
  ];
  foreach ($stylesList as $key => $label) {
    $element['styles'][$key][$key] = [
      '#type' => 'markup',
      '#markup' => $label,
    ];
  }
  $element['default'] = [
    '#title' => t('Default style'),
    '#type' => 'select',
    '#options' => $stylesList,
    '#default_value' => $settings['default'],
    '#description' => t('Select the style which will be selected by default or used if no specific styles above are enabled.'),
    '#weight' => 23,
  ];
  if ($insertType === INSERT_TYPE_IMAGE) {
    $stylesList = InsertUtility::stylesListToOptions(array_diff_key($stylesLists[INSERT_TYPE_IMAGE], $stylesLists[INSERT_TYPE_FILE]));
    $element['auto_image_style'] = [
      '#title' => t('Automatic option image style'),
      '#type' => 'select',
      '#options' => $stylesList,
      '#default_value' => $settings['auto_image_style'],
      '#description' => t('The style to be used when inserting images using the AUTOMATIC insert style option.'),
      '#weight' => 24,
    ];
    $element['link_image'] = [
      '#title' => t('Link image to'),
      '#type' => 'select',
      '#options' => array_merge([
        NULL => t('do not link'),
      ], $stylesList),
      '#default_value' => $settings['link_image'],
      '#description' => t('Select the style of the image the image shall link to.'),
      '#weight' => 25,
    ];
    $element['caption'] = [
      '#type' => 'checkbox',
      '#title' => t('Apply caption to images'),
      '#default_value' => $settings['caption'],
      '#description' => t('Applies a <code>data-caption</code> attribute to images. Transformation into an actual caption is performed by the caption filter that needs to be enabled for the text format in use. See text format configuration per @content_authoring and ensure <em>Caption images</em> in the <em>Enabled filters</em> section is checked. By default, the image title input field content will be used as caption.', [
        '@content_authoring' => Link::fromTextAndUrl(t('content authoring admin page'), Url::fromRoute('filter.admin_overview'))
          ->toString(),
      ]),
      '#weight' => 25,
    ];
    $element['width'] = [
      '#title' => t('Maximum image insert width'),
      '#type' => 'textfield',
      '#size' => 10,
      '#field_suffix' => ' ' . t('pixels'),
      '#default_value' => $settings['width'],
      '#description' => t('When inserting images, the height and width of images may be scaled down to fit within the specified width. Note that this does not resize the image, it only affects the HTML output.'),
      '#weight' => 26,
    ];
    $element['align'] = [
      '#type' => 'checkbox',
      '#title' => t('Alignment controls'),
      '#default_value' => $settings['align'],
      '#description' => t('Alignment may be applied using radio buttons.'),
      '#weight' => 27,
    ];
    $element['rotate'] = [
      '#type' => 'checkbox',
      '#title' => t('Rotation controls'),
      '#default_value' => $settings['rotate'],
      '#description' => t('The image may be rotated by using rotation controls.'),
      '#weight' => 28,
    ];
  }
  return $element;
}