public function FormHelper::displayEntitySettings in Simple XML sitemap 4.x
Same name and namespace in other branches
- 8.3 src/Form/FormHelper.php \Drupal\simple_sitemap\Form\FormHelper::displayEntitySettings()
- 8.2 src/Form/FormHelper.php \Drupal\simple_sitemap\Form\FormHelper::displayEntitySettings()
@todo Refactor.
Parameters
$form_fragment:
Return value
$this
File
- src/
Form/ FormHelper.php, line 298
Class
- FormHelper
- Class FormHelper
Namespace
Drupal\simple_sitemap\FormCode
public function displayEntitySettings(&$form_fragment) : FormHelper {
$bundle_name = !empty($this
->getBundleName()) ? $this->entityHelper
->getBundleLabel($this
->getEntityTypeId(), $this
->getBundleName()) : $this
->t('undefined');
$variants = SimpleSitemap::loadMultiple();
$form_fragment['settings']['#markup'] = empty($variants) ? $this
->t('At least one sitemap needs to be defined for a bundle to be indexable.<br>Sitemaps can be configured <a href="@url">here</a>.', [
'@url' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap',
]) : '<strong>' . $this
->t('Sitemaps') . '</strong>';
foreach ($variants as $variant_id => $variant) {
$form_fragment['settings'][$variant_id] = [
'#type' => 'details',
'#title' => '<em>' . $this
->t($variant
->label()) . '</em>',
'#open' => !empty($this->bundleSettings[$variant_id]['index']),
];
// Disable fields of entity instance whose bundle is not indexed.
$form_fragment['settings'][$variant_id]['#disabled'] = $this
->getEntityCategory() === 'instance' && empty($this->bundleSettings[$variant_id]['bundle_settings']['index']);
// Index
$form_fragment['settings'][$variant_id]['index_' . $variant_id . '_' . $this
->getEntityTypeId() . '_settings'] = [
'#type' => 'radios',
'#default_value' => (int) $this->bundleSettings[$variant_id]['index'],
'#options' => [
$this
->getEntityCategory() === 'instance' ? $this
->t('Do not index this <em>@bundle</em> entity in variant <em>@variant_label</em>', [
'@bundle' => $bundle_name,
'@variant_label' => $this
->t($variant
->label()),
]) : $this
->t('Do not index entities of type <em>@bundle</em> in variant <em>@variant_label</em>', [
'@bundle' => $bundle_name,
'@variant_label' => $this
->t($variant
->label()),
]),
$this
->getEntityCategory() === 'instance' ? $this
->t('Index this <em>@bundle entity</em> in variant <em>@variant_label</em>', [
'@bundle' => $bundle_name,
'@variant_label' => $this
->t($variant
->label()),
]) : $this
->t('Index entities of type <em>@bundle</em> in variant <em>@variant_label</em>', [
'@bundle' => $bundle_name,
'@variant_label' => $this
->t($variant
->label()),
]),
],
'#attributes' => [
'class' => [
'enabled-for-variant',
$variant_id,
],
],
];
if ($this
->getEntityCategory() === 'instance' && isset($this->bundleSettings[$variant_id]['bundle_settings']['index'])) {
$form_fragment['settings'][$variant_id]['index_' . $variant_id . '_' . $this
->getEntityTypeId() . '_settings']['#options'][(int) $this->bundleSettings[$variant_id]['bundle_settings']['index']] .= ' <em>(' . $this
->t('default') . ')</em>';
}
// Priority
$form_fragment['settings'][$variant_id]['priority_' . $variant_id . '_' . $this
->getEntityTypeId() . '_settings'] = [
'#type' => 'select',
'#title' => $this
->t('Priority'),
'#description' => $this
->getEntityCategory() === 'instance' ? $this
->t('The priority this <em>@bundle</em> 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' => $this->bundleSettings[$variant_id]['priority'],
'#options' => $this
->getPrioritySelectValues(),
'#states' => [
'visible' => [
':input[name="index_' . $variant_id . '_' . $this
->getEntityTypeId() . '_settings"]' => [
'value' => 1,
],
],
],
];
if ($this
->getEntityCategory() === 'instance' && isset($this->bundleSettings[$variant_id]['bundle_settings']['priority'])) {
$form_fragment['settings'][$variant_id]['priority_' . $variant_id . '_' . $this
->getEntityTypeId() . '_settings']['#options'][$this
->formatPriority($this->bundleSettings[$variant_id]['bundle_settings']['priority'])] .= ' (' . $this
->t('default') . ')';
}
// Changefreq
$form_fragment['settings'][$variant_id]['changefreq_' . $variant_id . '_' . $this
->getEntityTypeId() . '_settings'] = [
'#type' => 'select',
'#title' => $this
->t('Change frequency'),
'#description' => $this
->getEntityCategory() === 'instance' ? $this
->t('The frequency with which this <em>@bundle</em> 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' => isset($this->bundleSettings[$variant_id]['changefreq']) ? $this->bundleSettings[$variant_id]['changefreq'] : NULL,
'#options' => $this
->getChangefreqSelectValues(),
'#states' => [
'visible' => [
':input[name="index_' . $variant_id . '_' . $this
->getEntityTypeId() . '_settings"]' => [
'value' => 1,
],
],
],
];
if ($this
->getEntityCategory() === 'instance' && isset($this->bundleSettings[$variant_id]['bundle_settings']['changefreq'])) {
$form_fragment['settings'][$variant_id]['changefreq_' . $variant_id . '_' . $this
->getEntityTypeId() . '_settings']['#options'][$this->bundleSettings[$variant_id]['bundle_settings']['changefreq']] .= ' (' . $this
->t('default') . ')';
}
// Images
$form_fragment['settings'][$variant_id]['include_images_' . $variant_id . '_' . $this
->getEntityTypeId() . '_settings'] = [
'#type' => 'select',
'#title' => $this
->t('Include images'),
'#description' => $this
->getEntityCategory() === 'instance' ? $this
->t('Determines if images referenced by this <em>@bundle</em> 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' => isset($this->bundleSettings[$variant_id]['include_images']) ? (int) $this->bundleSettings[$variant_id]['include_images'] : 0,
'#options' => [
$this
->t('No'),
$this
->t('Yes'),
],
'#states' => [
'visible' => [
':input[name="index_' . $variant_id . '_' . $this
->getEntityTypeId() . '_settings"]' => [
'value' => 1,
],
],
],
];
if ($this
->getEntityCategory() === 'instance' && isset($this->bundleSettings[$variant_id]['bundle_settings']['include_images'])) {
$form_fragment['settings'][$variant_id]['include_images_' . $variant_id . '_' . $this
->getEntityTypeId() . '_settings']['#options'][(int) $this->bundleSettings[$variant_id]['bundle_settings']['include_images']] .= ' (' . $this
->t('default') . ')';
}
}
return $this;
}