Commit 6eaf7eff authored by gbyte.co's avatar gbyte.co

Multiple variants UI WIP

parent f764181f
...@@ -62,12 +62,17 @@ class FormHelper { ...@@ -62,12 +62,17 @@ class FormHelper {
/** /**
* @var array * @var array
*/ */
protected $bundleSettings; protected $settings;
/** // /**
* @var array // * @var array
*/ // */
protected $instanceSettings; // protected $bundleSettings;
//
// /**
// * @var array
// */
// protected $instanceSettings;
/** /**
* @var array * @var array
...@@ -260,11 +265,14 @@ class FormHelper { ...@@ -260,11 +265,14 @@ class FormHelper {
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/ */
public function negotiateSettings() { public function negotiateSettings() {
$this->bundleSettings = $this->generator->setVariants(TRUE)
->getBundleSettings($this->getEntityTypeId(), $this->getBundleName(), FALSE, TRUE);
if ($this->getEntityCategory() === 'instance' && NULL !== $this->getInstanceId()) { if ($this->getEntityCategory() === 'instance' && NULL !== $this->getInstanceId()) {
$this->instanceSettings = $this->generator->setVariants(TRUE)->getEntityInstanceSettings($this->getEntityTypeId(), $this->getInstanceId()); $this->settings = $this->generator->setVariants(TRUE)
->getEntityInstanceSettings($this->getEntityTypeId(), $this->getInstanceId());
//todo Should spit out variant => settings and not just settings; to do this, alter getEntityInstanceSettings() to include 'multiple variants' option.
}
else {
$this->settings = $this->generator->setVariants(TRUE)
->getBundleSettings($this->getEntityTypeId(), $this->getBundleName(), TRUE, TRUE);
} }
return $this; return $this;
...@@ -278,45 +286,49 @@ class FormHelper { ...@@ -278,45 +286,49 @@ class FormHelper {
public function displayEntitySettings(&$form_fragment, $multiple = FALSE) { public function displayEntitySettings(&$form_fragment, $multiple = FALSE) {
$prefix = $multiple ? $this->getEntityTypeId() . '_' : ''; $prefix = $multiple ? $this->getEntityTypeId() . '_' : '';
$bundle_name = !empty($this->getBundleName()) ? $this->getBundleName() : $this->t('undefined'); $bundle_name = !empty($this->getBundleName()) ? $this->getBundleName() : $this->t('undefined');
$settings = $this->getEntityCategory() === 'instance' ? $this->instanceSettings : $this->bundleSettings; // Simplesitemap::supplementDefaultSettings('entity', $settings); // todo: necessary?
Simplesitemap::supplementDefaultSettings('entity', $settings);
// Variants // Variants
$variants = array_keys($settings); // $variants = $this->generator->getSitemapManager()->getSitemapVariants(NULL, FALSE); $variants = $this->generator->getSitemapManager()->getSitemapVariants(NULL, FALSE);
$indexed_variants = []; foreach ($variants as $variant => $definition) {
foreach ($variants as $variant) { $form_fragment[$prefix . 'simple_sitemap_variant_' . $variant] = [
if (!empty($settings[$variant]['index'])) { '#type' => 'details',
$indexed_variants[] = $variant; '#title' => '<em>' . $definition['label'] . '</em>',
} '#open' => !empty($this->settings[$variant]['index']),
} // '#description' => !empty($type_definition['description']) ? '<div class="description">' . $type_definition['description'] . '</div>' : '',
$form_fragment[$prefix . 'simple_sitemap_variant'] = [
'#type' => 'select',
'#title' => $this->t('Sitemap variants'),
'#description' => $this->t('The sitemap variants entities of this type are to be indexed in.'),
'#options' => array_map(function($variants) { return $this->t($variants['label']); }, $variants),
'#disabled' => $this->getEntityCategory() === 'instance',
'#default_value' => $indexed_variants,
];
// Index
if (!$multiple) {
$form_fragment[$prefix . 'simple_sitemap_index_content'] = [
'#type' => 'radios',
'#default_value' => (int) $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($this->bundleSettings['index'])) { // Index
$form_fragment[$prefix . 'simple_sitemap_index_content']['#options'][(int) $this->bundleSettings['index']] .= ' <em>(' . $this->t('default') . ')</em>'; if (!$multiple) {
$form_fragment[$prefix . 'simple_sitemap_variant_' . $variant]['index_content'] = [
'#type' => 'radios',
'#default_value' => (int) $this->settings[$variant]['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($this->bundleSettings[$variant]['index'])) {
$form_fragment[$prefix . 'simple_sitemap_index_content']['#options'][(int) $this->settings[$variant]['index']] .= ' <em>(' . $this->t('default') . ')</em>';
}
} }
} }
// $form_fragment[$prefix . 'simple_sitemap_variant'] = [
// '#type' => 'select',
// '#title' => $this->t('Sitemap variants'),
// '#description' => $this->t('The sitemap variants entities of this type are to be indexed in.'),
// '#options' => array_map(function($variants) { return $this->t($variants['label']); }, $variants),
// '#disabled' => $this->getEntityCategory() === 'instance',
// '#default_value' => $indexed_variants,
// ];
// //
// // Variant // // Variant
// $form_fragment[$prefix . 'simple_sitemap_variant'] = [ // $form_fragment[$prefix . 'simple_sitemap_variant'] = [
...@@ -336,7 +348,7 @@ class FormHelper { ...@@ -336,7 +348,7 @@ class FormHelper {
// '#disabled' => $this->getEntityCategory() === 'instance', // '#disabled' => $this->getEntityCategory() === 'instance',
// ]; // ];
// Priority /* // Priority
$form_fragment[$prefix . 'simple_sitemap_priority'] = [ $form_fragment[$prefix . 'simple_sitemap_priority'] = [
'#type' => 'select', '#type' => 'select',
'#title' => $this->t('Priority'), '#title' => $this->t('Priority'),
...@@ -394,7 +406,7 @@ class FormHelper { ...@@ -394,7 +406,7 @@ class FormHelper {
if ($this->getEntityCategory() === 'instance' && isset($this->bundleSettings['include_images'])) { if ($this->getEntityCategory() === 'instance' && isset($this->bundleSettings['include_images'])) {
$form_fragment[$prefix . 'simple_sitemap_include_images']['#options'][(int) $this->bundleSettings['include_images']] .= ' (' . $this->t('default') . ')'; $form_fragment[$prefix . 'simple_sitemap_include_images']['#options'][(int) $this->bundleSettings['include_images']] .= ' (' . $this->t('default') . ')';
} }*/
return $this; return $this;
} }
......
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