You are here

public static function FlushSingleImageForm::checkStyles in Flush Single Image Styles 8

Ajax callback to check which styles an image has cached.

File

src/Form/FlushSingleImageForm.php, line 148

Class

FlushSingleImageForm
Class FlushSingleImageForm.

Namespace

Drupal\flush_single_image\Form

Code

public static function checkStyles(array &$form, FormStateInterface $form_state) {
  $paths = \Drupal::service('flush_single_image')
    ->flush($form_state
    ->getValue('path'));
  if ($paths) {
    $element = [
      '#theme' => 'item_list',
      '#title' => t('Styled Images for @path', [
        '@path' => $form_state
          ->getValue('path'),
      ]),
      '#prefix' => '<div id="flush-single-image-description">',
      '#suffix' => '</div>',
      '#items' => [],
    ];
    foreach ($paths as $path) {
      $element['#items'][] = [
        '#markup' => $path,
      ];
    }
  }
  else {
    $element = [
      '#markup' => '<p class="description">There are no image styles cached for this image.</p>',
      '#prefix' => '<div id="flush-single-image-description">',
      '#suffix' => '</div>',
      '#title' => t('Check Styles'),
    ];
  }
  return $element;
}