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

Multiple variants UI WIP

parent f764181f
......@@ -62,12 +62,17 @@ class FormHelper {
/**
* @var array
*/
protected $bundleSettings;
protected $settings;
/**
* @var array
*/
protected $instanceSettings;
// /**
// * @var array
// */
// protected $bundleSettings;
//
// /**
// * @var array
// */
// protected $instanceSettings;
/**
* @var array
......@@ -260,11 +265,14 @@ class FormHelper {
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
public function negotiateSettings() {
$this->bundleSettings = $this->generator->setVariants(TRUE)
->getBundleSettings($this->getEntityTypeId(), $this->getBundleName(), FALSE, TRUE);
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;
......@@ -278,31 +286,23 @@ class FormHelper {
public function displayEntitySettings(&$form_fragment, $multiple = FALSE) {
$prefix = $multiple ? $this->getEntityTypeId() . '_' : '';
$bundle_name = !empty($this->getBundleName()) ? $this->getBundleName() : $this->t('undefined');
$settings = $this->getEntityCategory() === 'instance' ? $this->instanceSettings : $this->bundleSettings;
Simplesitemap::supplementDefaultSettings('entity', $settings);
// Simplesitemap::supplementDefaultSettings('entity', $settings); // todo: necessary?
// Variants
$variants = array_keys($settings); // $variants = $this->generator->getSitemapManager()->getSitemapVariants(NULL, FALSE);
$indexed_variants = [];
foreach ($variants as $variant) {
if (!empty($settings[$variant]['index'])) {
$indexed_variants[] = $variant;
}
}
$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,
$variants = $this->generator->getSitemapManager()->getSitemapVariants(NULL, FALSE);
foreach ($variants as $variant => $definition) {
$form_fragment[$prefix . 'simple_sitemap_variant_' . $variant] = [
'#type' => 'details',
'#title' => '<em>' . $definition['label'] . '</em>',
'#open' => !empty($this->settings[$variant]['index']),
// '#description' => !empty($type_definition['description']) ? '<div class="description">' . $type_definition['description'] . '</div>' : '',
];
// Index
if (!$multiple) {
$form_fragment[$prefix . 'simple_sitemap_index_content'] = [
$form_fragment[$prefix . 'simple_sitemap_variant_' . $variant]['index_content'] = [
'#type' => 'radios',
'#default_value' => (int) $settings['index'],
'#default_value' => (int) $this->settings[$variant]['index'],
'#options' => [
0 => $this->getEntityCategory() === 'instance'
? $this->t('Do not index this @bundle entity', ['@bundle' => $bundle_name])
......@@ -313,10 +313,22 @@ class FormHelper {
],
];
if ($this->getEntityCategory() === 'instance' && isset($this->bundleSettings['index'])) {
$form_fragment[$prefix . 'simple_sitemap_index_content']['#options'][(int) $this->bundleSettings['index']] .= ' <em>(' . $this->t('default') . ')</em>';
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
// $form_fragment[$prefix . 'simple_sitemap_variant'] = [
......@@ -336,7 +348,7 @@ class FormHelper {
// '#disabled' => $this->getEntityCategory() === 'instance',
// ];
// Priority
/* // Priority
$form_fragment[$prefix . 'simple_sitemap_priority'] = [
'#type' => 'select',
'#title' => $this->t('Priority'),
......@@ -394,7 +406,7 @@ class FormHelper {
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') . ')';
}
}*/
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