You are here

public function ImageStyles::getSettingsForm in Consumer Image Styles 8.3

Same name and namespace in other branches
  1. 4.x src/Plugin/jsonapi/FieldEnhancer/ImageStyles.php \Drupal\consumer_image_styles\Plugin\jsonapi\FieldEnhancer\ImageStyles::getSettingsForm()

File

src/Plugin/jsonapi/FieldEnhancer/ImageStyles.php, line 208

Class

ImageStyles
Perform additional manipulations to timestamp fields.

Namespace

Drupal\consumer_image_styles\Plugin\jsonapi\FieldEnhancer

Code

public function getSettingsForm(array $resource_field_info) {
  $options = [];
  $settings = empty($resource_field_info['enhancer']['settings']) ? $this
    ->getConfiguration() : $resource_field_info['enhancer']['settings'];
  foreach (ImageStyle::loadMultiple() as $style) {
    $options[$style
      ->id()] = $style
      ->label();
  }
  $refine_ref = 'resourceFields[' . $resource_field_info['fieldName'] . '][enhancer][settings][styles][refine]';
  return [
    'styles' => [
      '#type' => 'details',
      '#open' => TRUE,
      '#title' => $this
        ->t('Image Styles options'),
      '#tree' => TRUE,
      'refine' => [
        '#type' => 'checkbox',
        '#element_validate' => [
          [
            static::class,
            'stringToBool',
          ],
        ],
        '#title' => $this
          ->t('Refine selection?'),
        '#description' => $this
          ->t('Reduces the list of image styles in the output calculated from the Consumer configuration.'),
        '#default_value' => empty($settings['styles']['refine']) ? FALSE : $settings['styles']['refine'],
      ],
      'custom_selection' => [
        '#type' => 'checkboxes',
        '#element_validate' => [
          [
            static::class,
            'mappingToSequence',
          ],
        ],
        '#title' => $this
          ->t('Image Styles'),
        '#description' => $this
          ->t('Narrow down the image styles to display on this field. Note that any image styles selected here that are not allowed in the consumer making the HTTP request will not appear in the output.'),
        '#default_value' => empty($settings['styles']['custom_selection']) ? array_keys($options) : $settings['styles']['custom_selection'],
        '#options' => $options,
        '#states' => [
          'disabled' => [
            ':input[name="' . $refine_ref . '"]' => [
              'checked' => FALSE,
            ],
          ],
          'invisible' => [
            ':input[name="' . $refine_ref . '"]' => [
              'checked' => FALSE,
            ],
          ],
        ],
      ],
    ],
  ];
}