Commit d5533845 authored by WalkingDexter's avatar WalkingDexter Committed by atymchuk

Changed 'Sitemap views' admin page output.

parent 3e21daf2
/**
* @file
* Attaches simple_sitemap behaviors to the sitemap views form.
*/
(function ($, Drupal) {
Drupal.simpleSitemapSitemapViews = {};
Drupal.behaviors.simpleSitemapSitemapViewsForm = {
attach: function attach() {
var $form = $('[data-drupal-selector="simple-sitemap-views-form"]').once('simple-sitemap-sitemap-views-form');
if ($form.length) {
new Drupal.simpleSitemapSitemapViews.Form($form);
}
}
};
Drupal.simpleSitemapSitemapViews.Form = function ($form) {
this.$form = $form;
this.$enabled = $form.find('[data-drupal-selector="edit-enabled"]');
this.$details = $form.find('[data-drupal-selector="edit-indexed-displays"]');
this.$warning = $form.find('[data-drupal-selector="edit-warning"]');
this.$regenerate = $form.find('.form-item-simple-sitemap-regenerate-now');
this.$enabled.on('change', $.proxy(this, 'changeHandler'));
this.updateElementsDisplay();
this.$regenerate.hide();
};
Drupal.simpleSitemapSitemapViews.Form.prototype.changeHandler = function () {
this.updateElementsDisplay();
this.$regenerate.show();
};
Drupal.simpleSitemapSitemapViews.Form.prototype.updateElementsDisplay = function () {
if (this.$enabled.prop('checked')) {
this.$details.show();
this.$warning.hide();
}
else {
this.$details.hide();
this.$warning.show();
}
};
})(jQuery, Drupal);
\ No newline at end of file
......@@ -6,11 +6,3 @@ viewsUi:
- core/jquery
- core/drupal
- core/jquery.once
sitemapViews:
version: VERSION
js:
js/simple_sitemap.sitemapViews.js: {}
dependencies:
- core/jquery
- core/drupal
- core/jquery.once
simple_sitemap.settings_views:
path: '/admin/config/search/simplesitemap/views'
defaults:
_form: '\Drupal\simple_sitemap_views\Form\SimpleSitemapViewsForm'
_controller: '\Drupal\simple_sitemap_views\Controller\SimpleSitemapViewsController::content'
_title: 'Simple XML Sitemap Settings'
requirements:
_permission: 'administer sitemap settings'
<?php
/**
* @file
* Contains \Drupal\simple_sitemap_views\Controller\SimpleSitemapViewsController.
*/
namespace Drupal\simple_sitemap_views\Controller;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\simple_sitemap_views\SimpleSitemapViews;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Url;
/**
* Controller for Simple XML Sitemap Views admin page.
*/
class SimpleSitemapViewsController extends ControllerBase {
/**
* Views sitemap data.
*
* @var \Drupal\simple_sitemap_views\SimpleSitemapViews
*/
protected $sitemapViews;
/**
* SimpleSitemapViewsController constructor.
*
* @param \Drupal\simple_sitemap_views\SimpleSitemapViews $sitemap_views
* Views sitemap data.
*/
public function __construct(SimpleSitemapViews $sitemap_views) {
$this->sitemapViews = $sitemap_views;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('simple_sitemap.views')
);
}
/**
* Builds a listing of indexed views displays.
*
* @return array
* A render array.
*/
public function content() {
$table = [
'#type' => 'table',
'#header' => [
$this->t('View'),
$this->t('Display'),
$this->t('Arguments'),
$this->t('Operations'),
],
'#empty' => $this->t('No displays are set to be indexed yet.'),
];
foreach ($this->sitemapViews->getIndexableViews() as $index => $view) {
$table[$index]['view'] = ['#markup' => $view->storage->label()];
$table[$index]['display'] = ['#markup' => $view->display_handler->display['display_title']];
// Determine whether view display arguments are indexed.
$arguments_status = $this->sitemapViews->getIndexableArguments($view) ? $this->t('Yes') : $this->t('No');
$table[$index]['arguments'] = ['#markup' => $arguments_status];
// Link to view display edit form.
$display_edit_url = Url::fromRoute('entity.view.edit_display_form', [
'view' => $view->id(),
'display_id' => $view->current_display,
]);
$table[$index]['operations'] = [
'#type' => 'operations',
'#links' => [
'display_edit' => [
'title' => $this->t('Edit'),
'url' => $display_edit_url,
],
],
];
}
// Show information about indexed displays.
$build['indexed_displays'] = $table;
return $build;
}
}
<?php
/**
* @file
* Contains \Drupal\simple_sitemap_views\Form\SimpleSitemapViewsForm.
*/
namespace Drupal\simple_sitemap_views\Form;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\simple_sitemap\Form\SimplesitemapFormBase;
use Drupal\simple_sitemap_views\SimpleSitemapViews;
use Drupal\simple_sitemap\Form\FormHelper;
use Drupal\Core\Form\FormStateInterface;
use Drupal\simple_sitemap\Simplesitemap;
use Drupal\Core\Url;
/**
* Simple XML Sitemap Views settings form.
*/
class SimpleSitemapViewsForm extends SimplesitemapFormBase {
/**
* Views sitemap data.
*
* @var \Drupal\simple_sitemap_views\SimpleSitemapViews
*/
protected $sitemapViews;
/**
* SimpleSitemapViewsForm constructor.
*
* @param \Drupal\simple_sitemap\Simplesitemap $generator
* The simple_sitemap.generator service.
* @param \Drupal\simple_sitemap\Form\FormHelper $form_helper
* Simple XML Sitemap form helper.
* @param \Drupal\simple_sitemap_views\SimpleSitemapViews $sitemap_views
* Views sitemap data.
*/
public function __construct(Simplesitemap $generator, FormHelper $form_helper, SimpleSitemapViews $sitemap_views) {
parent::__construct($generator, $form_helper);
$this->sitemapViews = $sitemap_views;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('simple_sitemap.generator'),
$container->get('simple_sitemap.form_helper'),
$container->get('simple_sitemap.views')
);
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'simple_sitemap_views_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['simple_sitemap_views']['#prefix'] = $this->getDonationText();
$form['simple_sitemap_views']['views'] = [
'#title' => $this->t('Sitemap views'),
'#type' => 'fieldset',
'#markup' => '<div class="description">' . $this->t('Manage views support.') . '</div>',
];
$form['simple_sitemap_views']['views']['enabled'] = [
'#type' => 'checkbox',
'#title' => $this->t('Enable views support'),
'#description' => $this->t('Sitemap settings for views can be set on the display editing pages.'),
'#default_value' => $this->sitemapViews->isEnabled(),
];
$indexable_views = $this->sitemapViews->getIndexableViews();
if (empty($indexable_views)) {
$form['simple_sitemap_views']['views']['indexed_displays'] = [
'#type' => 'html_tag',
'#tag' => 'div',
'#value' => $this->t('No displays are set to be indexed yet.'),
];
}
else {
$table = [
'#type' => 'table',
'#header' => [
$this->t('View'),
$this->t('Display'),
$this->t('Arguments'),
$this->t('Operations'),
],
];
foreach ($indexable_views as $index => $view) {
$table[$index]['view'] = ['#markup' => $view->storage->label()];
$table[$index]['display'] = ['#markup' => $view->display_handler->display['display_title']];
// Determine whether view display arguments are indexed.
$arguments_status = $this->sitemapViews->getIndexableArguments($view) ? $this->t('Yes') : $this->t('No');
$table[$index]['arguments'] = ['#markup' => $arguments_status];
// Link to view display edit form.
$display_edit_url = Url::fromRoute('entity.view.edit_display_form', [
'view' => $view->id(),
'display_id' => $view->current_display,
]);
$table[$index]['operations'] = [
'#type' => 'operations',
'#links' => [
'display_edit' => [
'title' => $this->t('Edit'),
'url' => $display_edit_url,
],
],
];
}
// Show information about indexed displays.
$form['simple_sitemap_views']['views']['indexed_displays'] = [
'#type' => 'details',
'#title' => $this->t('Displays set to be indexed'),
'table' => $table,
];
// A warning message that is controlled by JavaScript.
$form['simple_sitemap_views']['views']['warning'] = [
'#type' => 'html_tag',
'#tag' => 'div',
'#value' => $this->t('<strong>Warning:</strong> The views sitemap data will be deleted after hitting <em>Save</em>.'),
];
}
$this->formHelper->displayRegenerateNow($form['simple_sitemap_views']['views']);
$form['#attached']['library'][] = 'simple_sitemap_views/sitemapViews';
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state->getValue('enabled') ? $this->sitemapViews->enable() : $this->sitemapViews->disable();
parent::submitForm($form, $form_state);
// Regenerate sitemaps according to user setting.
if ($form_state->getValue('simple_sitemap_regenerate_now')) {
$this->generator->generateSitemap();
}
}
}
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