You are here

protected function LazyForm::getEnabledFiltersAndFields in Lazy-load 8.3

Same name and namespace in other branches
  1. 8.2 src/Form/LazyForm.php \Drupal\lazy\Form\LazyForm::getEnabledFiltersAndFields()

Builds the status report for all enabled filter formats & field formatters.

1 call to LazyForm::getEnabledFiltersAndFields()
LazyForm::buildForm in src/Form/LazyForm.php
Form constructor.

File

src/Form/LazyForm.php, line 107

Class

LazyForm
Configure Lazy settings for this site.

Namespace

Drupal\lazy\Form

Code

protected function getEnabledFiltersAndFields() : void {
  $links = [];

  // Build links of text-formats.
  foreach (filter_formats() as $key => $filter) {
    if ($filter
      ->status() && ($filter_configuration = $filter
      ->filters()
      ->getConfiguration()) && isset($filter_configuration['lazy_filter']['status']) && $filter_configuration['lazy_filter']['status']) {
      $tags = $filter_configuration['lazy_filter']['settings'];
      $label = '';
      if ($tags['image'] && $tags['iframe']) {
        $label = $this
          ->t('(Images and IFrames)');
      }
      elseif ($tags['image']) {
        $label = $this
          ->t('(Images only)');
      }
      elseif ($tags['iframe']) {
        $label = $this
          ->t('(IFrames only)');
      }
      $links['filter'][$filter
        ->id()] = [
        'title' => $filter
          ->label() . ' ' . $label,
        'url' => Url::fromRoute('entity.filter_format.edit_form', [
          'filter_format' => $filter
            ->id(),
        ], [
          'query' => [
            'destination' => Url::fromRoute('lazy.config_form')
              ->toString(),
          ],
        ]),
      ];
    }
  }

  // Build links for fields.
  $config_keys = $this
    ->configFactory()
    ->listAll('core.entity_view_display.');
  foreach ($config_keys as $config_key) {
    $entity_view_display = $this
      ->config($config_key);
    $content = $entity_view_display
      ->get('content');
    $entity_type = $entity_view_display
      ->get('targetEntityType');
    foreach ($content as $field_name => $field) {
      if (isset($field['third_party_settings']['lazy']['lazy_image']) && $field['third_party_settings']['lazy']['lazy_image'] == TRUE) {
        if ($entity_type === 'paragraph') {
          $key = 'paragraphs_type';
        }
        elseif ($entity_type === 'taxonomy_term') {
          $key = 'taxonomy_vocabulary';
        }
        elseif ($entity_type === 'contact_message') {
          $key = 'contact_form';
        }
        else {
          $key = "{$entity_type}_type";
        }
        $entity_mode = $entity_view_display
          ->get('mode');
        $entity_bundle = $entity_view_display
          ->get('bundle');
        $field_name_and_mode = "{$field_name}-{$entity_mode}";
        $link_text = "{$entity_type}.{$entity_bundle}.{$field_name}.{$entity_mode}";
        $links['field'][$field_name_and_mode] = [
          'title' => $link_text,
          'url' => Url::fromRoute("entity.entity_view_display.{$entity_type}.view_mode", [
            $key => $entity_bundle,
            'view_mode_name' => $entity_mode,
          ], [
            'query' => [
              'destination' => Url::fromRoute('lazy.config_form')
                ->toString(),
            ],
          ]),
        ];
      }
    }
  }

  // Display a message listing all text-formats have lazy-loading enabled.
  $this
    ->addLazyStatusMessage($links, 'filter', $this
    ->t('The <strong>text-formats</strong> have lazy-loading enabled:'));

  // Display a message listing all fields have lazy-loading enabled.
  $this
    ->addLazyStatusMessage($links, 'field', $this
    ->t('The <strong>fields</strong> have lazy-loading enabled:'));
}