Commit 2f74a9d5 authored by gbyte.co's avatar gbyte.co

Check if form operation is on disallowed operations list instead of allowed operations list

parent ae21bd37
......@@ -28,7 +28,7 @@ function simple_sitemap_form_alter(&$form, $form_state, $form_id) {
'#type' => 'details',
'#group' => isset($form['additional_settings']) ? 'additional_settings' : 'advanced',
'#title' => t('Simple XML sitemap'),
'#description' => $f->entityCategory == 'instance' ? t('Settings for this specific entity can be overridden here.') : '',
'#description' => $f->entityCategory == 'instance' ? t('Settings for this entity can be overridden here.') : '',
];
// Attach some js magic to forms.
if ($f->entityTypeId != 'comment' || $f->entityCategory != 'instance') // todo: JS not working on comment entity form, hence disabling.
......
......@@ -24,7 +24,7 @@ class Form {
private $formState;
private $generator;
private static $allowedFormOperations = ['default', 'edit', 'add'];
private static $skipFormOperations = ['delete', 'cancel'];
private static $valuesToCheck = ['simple_sitemap_index_content', 'simple_sitemap_priority', 'simple_sitemap_regenerate_now'];
/**
......@@ -104,14 +104,15 @@ class Form {
}
$index = isset($settings['index']) ? $settings['index'] : 0;
$priority = isset($settings['priority']) ? $settings['priority'] : self::PRIORITY_DEFAULT;
$bundle_name = !empty($this->bundleName) ? $this->bundleName : t('undefined');
if (!$multiple) {
$form_fragment[$prefix . 'simple_sitemap_index_content'] = [
'#type' => 'radios',
'#default_value' => $index,
'#options' => [
0 => $this->entityCategory == 'instance' ? t('Do not index this entity') : t('Do not index entities of this type'),
1 => $this->entityCategory == 'instance' ? t('Index this entity') : t('Index entities of this type'),
0 => $this->entityCategory == 'instance' ? t('Do not index this @bundle entity', ['@bundle' => $bundle_name]) : t('Do not index entities of this type'),
1 => $this->entityCategory == 'instance' ? t('Index this @bundle entity', ['@bundle' => $bundle_name]) : t('Index entities of this type'),
]
];
if ($this->entityCategory == 'instance' && isset($bundle_settings['index'])) {
......@@ -119,15 +120,10 @@ class Form {
}
}
if ($this->entityCategory == 'instance') {
$priority_description = t('The priority this entity will have in the eyes of search engine bots.');
}
elseif (!$multiple) {
$priority_description = t('The priority entities of this bundle will have in the eyes of search engine bots.');
}
else {
if ($this->entityCategory == 'instance')
$priority_description = t('The priority this @bundle entity will have in the eyes of search engine bots.', ['@bundle' => $bundle_name]);
else
$priority_description = t('The priority entities of this type will have in the eyes of search engine bots.');
}
$form_fragment[$prefix . 'simple_sitemap_priority'] = [
'#type' => 'select',
'#title' => t('Priority'),
......@@ -198,7 +194,7 @@ class Form {
$form_object = $this->formState->getFormObject();
if (!is_null($form_object)
&& method_exists($form_object, 'getEntity')
&& in_array($form_object->getOperation(), self::$allowedFormOperations)) {
&& !in_array($form_object->getOperation(), self::$skipFormOperations)) {
return $form_object->getEntity();
}
return FALSE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment