You are here

public function FormHelper::displayEntitySettings in Simple XML sitemap 8.2

Same name and namespace in other branches
  1. 8.3 src/Form/FormHelper.php \Drupal\simple_sitemap\Form\FormHelper::displayEntitySettings()
  2. 4.x src/Form/FormHelper.php \Drupal\simple_sitemap\Form\FormHelper::displayEntitySettings()

Parameters

array $form_fragment:

bool $multiple:

Return value

$this

File

src/Form/FormHelper.php, line 228

Class

FormHelper
Class FormHelper @package Drupal\simple_sitemap\Form

Namespace

Drupal\simple_sitemap\Form

Code

public function displayEntitySettings(&$form_fragment, $multiple = FALSE) {
  $prefix = $multiple ? $this
    ->getEntityTypeId() . '_' : '';
  if ($this
    ->getEntityCategory() === 'instance') {
    $bundle_settings = $this->generator
      ->getBundleSettings($this
      ->getEntityTypeId(), $this
      ->getBundleName());
    $settings = NULL !== $this
      ->getInstanceId() ? $this->generator
      ->getEntityInstanceSettings($this
      ->getEntityTypeId(), $this
      ->getInstanceId()) : $bundle_settings;
  }
  else {
    $settings = $this->generator
      ->getBundleSettings($this
      ->getEntityTypeId(), $this
      ->getBundleName());
  }
  Simplesitemap::supplementDefaultSettings('entity', $settings, [
    'index' => 0,
  ]);
  $bundle_name = !empty($this
    ->getBundleName()) ? $this
    ->getBundleName() : $this
    ->t('undefined');

  // Index
  if (!$multiple) {
    $form_fragment[$prefix . 'simple_sitemap_index_content'] = [
      '#type' => 'radios',
      '#default_value' => $settings['index'],
      '#options' => [
        0 => $this
          ->getEntityCategory() === 'instance' ? $this
          ->t('Do not index this @bundle entity', [
          '@bundle' => $bundle_name,
        ]) : $this
          ->t('Do not index entities of this type'),
        1 => $this
          ->getEntityCategory() === 'instance' ? $this
          ->t('Index this @bundle entity', [
          '@bundle' => $bundle_name,
        ]) : $this
          ->t('Index entities of this type'),
      ],
    ];
    if ($this
      ->getEntityCategory() === 'instance' && isset($bundle_settings['index'])) {
      $form_fragment[$prefix . 'simple_sitemap_index_content']['#options'][$bundle_settings['index']] .= ' <em>(' . $this
        ->t('default') . ')</em>';
    }
  }

  // Priority
  $form_fragment[$prefix . 'simple_sitemap_priority'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Priority'),
    '#description' => $this
      ->getEntityCategory() === 'instance' ? $this
      ->t('The priority this @bundle entity will have in the eyes of search engine bots.', [
      '@bundle' => $bundle_name,
    ]) : $this
      ->t('The priority entities of this type will have in the eyes of search engine bots.'),
    '#default_value' => $settings['priority'],
    '#options' => $this
      ->getPrioritySelectValues(),
  ];
  if ($this
    ->getEntityCategory() === 'instance' && isset($bundle_settings['priority'])) {
    $form_fragment[$prefix . 'simple_sitemap_priority']['#options'][$this
      ->formatPriority($bundle_settings['priority'])] .= ' (' . $this
      ->t('default') . ')';
  }

  // Changefreq
  $form_fragment[$prefix . 'simple_sitemap_changefreq'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Change frequency'),
    '#description' => $this
      ->getEntityCategory() === 'instance' ? $this
      ->t('The frequency with which this @bundle entity changes. Search engine bots may take this as an indication of how often to index it.', [
      '@bundle' => $bundle_name,
    ]) : $this
      ->t('The frequency with which entities of this type change. Search engine bots may take this as an indication of how often to index them.'),
    '#default_value' => $settings['changefreq'],
    '#options' => $this
      ->getChangefreqSelectValues(),
  ];
  if ($this
    ->getEntityCategory() === 'instance' && isset($bundle_settings['changefreq'])) {
    $form_fragment[$prefix . 'simple_sitemap_changefreq']['#options'][$bundle_settings['changefreq']] .= ' (' . $this
      ->t('default') . ')';
  }

  // Images
  $form_fragment[$prefix . 'simple_sitemap_include_images'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Include images'),
    '#description' => $this
      ->getEntityCategory() === 'instance' ? $this
      ->t('Determines if images referenced by this @bundle entity should be included in the sitemap.', [
      '@bundle' => $bundle_name,
    ]) : $this
      ->t('Determines if images referenced by entities of this type should be included in the sitemap.'),
    '#default_value' => $settings['include_images'],
    '#options' => [
      0 => $this
        ->t('No'),
      1 => $this
        ->t('Yes'),
    ],
  ];
  if ($this
    ->getEntityCategory() === 'instance' && isset($bundle_settings['include_images'])) {
    $form_fragment[$prefix . 'simple_sitemap_include_images']['#options'][$bundle_settings['include_images']] .= ' (' . $this
      ->t('default') . ')';
  }
  return $this;
}