updated core from 8.4 to 8.5 : bug with login_destination
This commit is contained in:
@@ -4,10 +4,11 @@ namespace Drupal\system\EventSubscriber;
|
||||
|
||||
use Drupal\Core\Routing\RouteSubscriberBase;
|
||||
use Drupal\Core\Routing\RoutingEvents;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
/**
|
||||
* Adds the _admin_route option to each admin route.
|
||||
* Adds the _admin_route option to each admin HTML route.
|
||||
*/
|
||||
class AdminRouteSubscriber extends RouteSubscriberBase {
|
||||
|
||||
@@ -16,7 +17,7 @@ class AdminRouteSubscriber extends RouteSubscriberBase {
|
||||
*/
|
||||
protected function alterRoutes(RouteCollection $collection) {
|
||||
foreach ($collection->all() as $route) {
|
||||
if (strpos($route->getPath(), '/admin') === 0 && !$route->hasOption('_admin_route')) {
|
||||
if (strpos($route->getPath(), '/admin') === 0 && !$route->hasOption('_admin_route') && static::isHtmlRoute($route)) {
|
||||
$route->setOption('_admin_route', TRUE);
|
||||
}
|
||||
}
|
||||
@@ -36,4 +37,19 @@ class AdminRouteSubscriber extends RouteSubscriberBase {
|
||||
return $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the given route is a HTML route.
|
||||
*
|
||||
* @param \Symfony\Component\Routing\Route $route
|
||||
* The route to analyze.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if HTML is a valid format for this route.
|
||||
*/
|
||||
protected static function isHtmlRoute(Route $route) {
|
||||
// If a route has no explicit format, then HTML is valid.
|
||||
$format = $route->hasRequirement('_format') ? explode('|', $route->getRequirement('_format')) : ['html'];
|
||||
return in_array('html', $format, TRUE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ use Drupal\Core\Form\ConfigFormBaseTrait;
|
||||
|
||||
/**
|
||||
* Configure cron settings for this site.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class CronForm extends FormBase {
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Provides a form for adding a date format.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class DateFormatAddForm extends DateFormatFormBase {
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Builds a form to delete a date format.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class DateFormatDeleteForm extends EntityDeleteForm {
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Provides a form for editing a date format.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class DateFormatEditForm extends DateFormatFormBase {
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Configure file system settings for this site.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class FileSystemForm extends ConfigFormBase {
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Configures image toolkit settings for this site.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class ImageToolkitForm extends ConfigFormBase {
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Configure logging settings for this site.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class LoggingForm extends ConfigFormBase {
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Builds a confirmation form for enabling modules with dependencies.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class ModulesListConfirmForm extends ConfirmFormBase {
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ namespace Drupal\system\Form;
|
||||
|
||||
/**
|
||||
* Builds a confirmation form for enabling experimental modules.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class ModulesListExperimentalConfirmForm extends ModulesListConfirmForm {
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
* each module's name, description, and information about which modules it
|
||||
* requires. See \Drupal\Core\Extension\InfoParser for info on module.info.yml
|
||||
* descriptors.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class ModulesListForm extends FormBase {
|
||||
|
||||
@@ -176,6 +178,7 @@ class ModulesListForm extends FormBase {
|
||||
// Lastly, sort all packages by title.
|
||||
uasort($form['modules'], ['\Drupal\Component\Utility\SortArray', 'sortByTitleProperty']);
|
||||
|
||||
$form['#attached']['library'][] = 'core/drupal.tableresponsive';
|
||||
$form['#attached']['library'][] = 'system/drupal.system.modules';
|
||||
$form['actions'] = ['#type' => 'actions'];
|
||||
$form['actions']['submit'] = [
|
||||
@@ -386,7 +389,7 @@ class ModulesListForm extends FormBase {
|
||||
}
|
||||
|
||||
// Add all dependencies to a list.
|
||||
while (list($module) = each($modules['install'])) {
|
||||
foreach ($modules['install'] as $module => $value) {
|
||||
foreach (array_keys($data[$module]->requires) as $dependency) {
|
||||
if (!isset($modules['install'][$dependency]) && !$this->moduleHandler->moduleExists($dependency)) {
|
||||
$modules['dependencies'][$module][$dependency] = $data[$dependency]->info['name'];
|
||||
|
||||
@@ -14,6 +14,8 @@ use Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface;
|
||||
|
||||
/**
|
||||
* Builds a confirmation form to uninstall selected modules.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class ModulesUninstallConfirmForm extends ConfirmFormBase {
|
||||
use ConfigDependencyDeleteFormTrait;
|
||||
|
||||
@@ -11,6 +11,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides a form for uninstalling modules.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class ModulesUninstallForm extends FormBase {
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Configure performance settings for this site.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class PerformanceForm extends ConfigFormBase {
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
* Provides a form removing module content entities data before uninstallation.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class PrepareModulesEntityUninstallForm extends ConfirmFormBase {
|
||||
|
||||
@@ -225,7 +227,7 @@ class PrepareModulesEntityUninstallForm extends ConfirmFormBase {
|
||||
$storage->delete($entities);
|
||||
}
|
||||
// Sometimes deletes cause secondary deletes. For example, deleting a
|
||||
// taxonomy term can cause it's children to be be deleted too.
|
||||
// taxonomy term can cause its children to be be deleted too.
|
||||
$context['sandbox']['progress'] = $context['sandbox']['max'] - $storage->getQuery()->count()->execute();
|
||||
|
||||
// Inform the batch engine that we are not finished and provide an
|
||||
|
||||
@@ -10,6 +10,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Configure regional settings for this site.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class RegionalForm extends ConfigFormBase {
|
||||
|
||||
|
||||
@@ -6,7 +6,9 @@ use Drupal\Core\Form\ConfigFormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Configure RSS settings for this site.
|
||||
* Configure RSS settings for this site
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class RssFeedsForm extends ConfigFormBase {
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Configure site information settings for this site.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class SiteInformationForm extends ConfigFormBase {
|
||||
|
||||
@@ -172,7 +174,7 @@ class SiteInformationForm extends ConfigFormBase {
|
||||
|
||||
}
|
||||
if (!$this->pathValidator->isValid($form_state->getValue('site_frontpage'))) {
|
||||
$form_state->setErrorByName('site_frontpage', $this->t("The path '%path' is either invalid or you do not have access to it.", ['%path' => $form_state->getValue('site_frontpage')]));
|
||||
$form_state->setErrorByName('site_frontpage', $this->t("Either the path '%path' is invalid or you do not have access to it.", ['%path' => $form_state->getValue('site_frontpage')]));
|
||||
}
|
||||
// Get the normal paths of both error pages.
|
||||
if (!$form_state->isValueEmpty('site_403')) {
|
||||
@@ -189,11 +191,11 @@ class SiteInformationForm extends ConfigFormBase {
|
||||
}
|
||||
// Validate 403 error path.
|
||||
if (!$form_state->isValueEmpty('site_403') && !$this->pathValidator->isValid($form_state->getValue('site_403'))) {
|
||||
$form_state->setErrorByName('site_403', $this->t("The path '%path' is either invalid or you do not have access to it.", ['%path' => $form_state->getValue('site_403')]));
|
||||
$form_state->setErrorByName('site_403', $this->t("Either the path '%path' is invalid or you do not have access to it.", ['%path' => $form_state->getValue('site_403')]));
|
||||
}
|
||||
// Validate 404 error path.
|
||||
if (!$form_state->isValueEmpty('site_404') && !$this->pathValidator->isValid($form_state->getValue('site_404'))) {
|
||||
$form_state->setErrorByName('site_404', $this->t("The path '%path' is either invalid or you do not have access to it.", ['%path' => $form_state->getValue('site_404')]));
|
||||
$form_state->setErrorByName('site_404', $this->t("Either the path '%path' is invalid or you do not have access to it.", ['%path' => $form_state->getValue('site_404')]));
|
||||
}
|
||||
|
||||
parent::validateForm($form, $form_state);
|
||||
|
||||
@@ -11,6 +11,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Configure maintenance settings for this site.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class SiteMaintenanceModeForm extends ConfigFormBase {
|
||||
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\system\Form;
|
||||
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Plugin\PluginFormBase;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* The settings_tray form handler for the SystemBrandingBlock.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class SystemBrandingOffCanvasForm extends PluginFormBase implements ContainerInjectionInterface {
|
||||
|
||||
/**
|
||||
* The block plugin.
|
||||
*
|
||||
* @var \Drupal\Core\Block\BlockPluginInterface
|
||||
*/
|
||||
protected $plugin;
|
||||
|
||||
/**
|
||||
* The config factory.
|
||||
*
|
||||
* @var \Drupal\Core\Config\ConfigFactoryInterface
|
||||
*/
|
||||
protected $configFactory;
|
||||
|
||||
/**
|
||||
* The current user.
|
||||
*
|
||||
* @var \Drupal\Core\Session\AccountInterface
|
||||
*/
|
||||
protected $currentUser;
|
||||
|
||||
/**
|
||||
* SystemBrandingOffCanvasForm constructor.
|
||||
*
|
||||
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
|
||||
* The config factory.
|
||||
* @param \Drupal\Core\Session\AccountInterface $current_user
|
||||
* The current user.
|
||||
*/
|
||||
public function __construct(ConfigFactoryInterface $config_factory, AccountInterface $current_user) {
|
||||
$this->configFactory = $config_factory;
|
||||
$this->currentUser = $current_user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('config.factory'),
|
||||
$container->get('current_user')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
|
||||
$form = $this->plugin->buildConfigurationForm($form, $form_state);
|
||||
|
||||
$form['block_branding']['#type'] = 'details';
|
||||
$form['block_branding']['#weight'] = 10;
|
||||
|
||||
// Unset links to Site Information form, we can make these changes here.
|
||||
unset($form['block_branding']['use_site_name']['#description'], $form['block_branding']['use_site_slogan']['#description']);
|
||||
|
||||
$site_config = $this->configFactory->getEditable('system.site');
|
||||
// Load the immutable config to load the overrides.
|
||||
$site_config_immutable = $this->configFactory->get('system.site');
|
||||
$form['site_information'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => t('Site details'),
|
||||
'#open' => TRUE,
|
||||
'#access' => $this->currentUser->hasPermission('administer site configuration') && !$site_config_immutable->hasOverrides('name') && !$site_config_immutable->hasOverrides('slogan'),
|
||||
];
|
||||
$form['site_information']['site_name'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Site name'),
|
||||
'#default_value' => $site_config->get('name'),
|
||||
'#required' => TRUE,
|
||||
];
|
||||
$form['site_information']['site_slogan'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Slogan'),
|
||||
'#default_value' => $site_config->get('slogan'),
|
||||
'#description' => t("How this is used depends on your site's theme."),
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
|
||||
$this->plugin->validateConfigurationForm($form, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
|
||||
$site_config = $this->configFactory->get('system.site');
|
||||
if (AccessResult::allowedIf(!$site_config->hasOverrides('name') && !$site_config->hasOverrides('slogan'))->isAllowed()) {
|
||||
$site_info = $form_state->getValue('site_information');
|
||||
$this->configFactory->getEditable('system.site')
|
||||
->set('name', $site_info['site_name'])
|
||||
->set('slogan', $site_info['site_slogan'])
|
||||
->save();
|
||||
}
|
||||
|
||||
$this->plugin->submitConfigurationForm($form, $form_state);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\system\Form;
|
||||
|
||||
use Drupal\Component\Plugin\PluginInspectionInterface;
|
||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Plugin\PluginFormBase;
|
||||
use Drupal\Core\Render\Element;
|
||||
use Drupal\Core\Routing\RedirectDestinationTrait;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
use Drupal\Core\StringTranslation\TranslationInterface;
|
||||
use Drupal\system\MenuInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* The setting_tray form handler for the SystemMenuBlock.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class SystemMenuOffCanvasForm extends PluginFormBase implements ContainerInjectionInterface {
|
||||
|
||||
use StringTranslationTrait;
|
||||
use RedirectDestinationTrait;
|
||||
|
||||
/**
|
||||
* The plugin.
|
||||
*
|
||||
* @var \Drupal\Core\Block\BlockPluginInterface
|
||||
*/
|
||||
protected $plugin;
|
||||
|
||||
/**
|
||||
* The menu entity that the block uses and that will be edited in this form.
|
||||
*
|
||||
* @var \Drupal\system\MenuInterface
|
||||
*/
|
||||
protected $menu;
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\Entity\EntityStorageInterface
|
||||
*/
|
||||
protected $menuStorage;
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The config factory.
|
||||
*
|
||||
* @var \Drupal\Core\Config\ConfigFactoryInterface
|
||||
*/
|
||||
protected $configFactory;
|
||||
|
||||
/**
|
||||
* SystemMenuOffCanvasForm constructor.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityStorageInterface $menu_storage
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
|
||||
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
|
||||
* The config factory.
|
||||
*/
|
||||
public function __construct(EntityStorageInterface $menu_storage, EntityTypeManagerInterface $entity_type_manager, TranslationInterface $string_translation, ConfigFactoryInterface $config_factory) {
|
||||
$this->menuStorage = $menu_storage;
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
$this->stringTranslation = $string_translation;
|
||||
$this->configFactory = $config_factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('entity_type.manager')->getStorage('menu'),
|
||||
$container->get('entity_type.manager'),
|
||||
$container->get('string_translation'),
|
||||
$container->get('config.factory')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
|
||||
$form = $this->plugin->buildConfigurationForm([], $form_state);
|
||||
// Move the menu levels section to the bottom.
|
||||
$form['menu_levels']['#weight'] = 100;
|
||||
|
||||
$form['entity_form'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Edit menu %label', ['%label' => $this->menu->label()]),
|
||||
'#open' => TRUE,
|
||||
'#access' => !$this->hasMenuOverrides() && $this->menu->access('edit'),
|
||||
];
|
||||
$form['entity_form'] += $this->getEntityForm($this->menu)->buildForm([], $form_state);
|
||||
|
||||
// Print the menu link titles as text instead of a link.
|
||||
if (!empty($form['entity_form']['links']['links'])) {
|
||||
foreach (Element::children($form['entity_form']['links']['links']) as $child) {
|
||||
$title = $form['entity_form']['links']['links'][$child]['title'][1]['#title'];
|
||||
$form['entity_form']['links']['links'][$child]['title'][1] = ['#markup' => $title];
|
||||
}
|
||||
}
|
||||
// Change the header text.
|
||||
$form['entity_form']['links']['links']['#header'][0] = $this->t('Link');
|
||||
$form['entity_form']['links']['links']['#header'][1]['data'] = $this->t('On');
|
||||
|
||||
// Remove the label, ID, description, and buttons from the entity form.
|
||||
unset($form['entity_form']['label'], $form['entity_form']['id'], $form['entity_form']['description'], $form['entity_form']['actions']);
|
||||
// Since the overview form is further nested than expected, update the
|
||||
// #parents. See \Drupal\menu_ui\MenuForm::form().
|
||||
$form_state->set('menu_overview_form_parents', ['settings', 'entity_form', 'links']);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
|
||||
$this->plugin->validateConfigurationForm($form, $form_state);
|
||||
if (!$this->hasMenuOverrides()) {
|
||||
$this->getEntityForm($this->menu)->validateForm($form, $form_state);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
|
||||
$this->plugin->submitConfigurationForm($form, $form_state);
|
||||
if (!$this->hasMenuOverrides()) {
|
||||
$this->getEntityForm($this->menu)->submitForm($form, $form_state);
|
||||
$this->menu->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the entity form for this menu.
|
||||
*
|
||||
* @param \Drupal\system\MenuInterface $menu
|
||||
* The menu entity.
|
||||
*
|
||||
* @return \Drupal\Core\Entity\EntityFormInterface
|
||||
* The entity form.
|
||||
*/
|
||||
protected function getEntityForm(MenuInterface $menu) {
|
||||
$entity_form = $this->entityTypeManager->getFormObject('menu', 'edit');
|
||||
$entity_form->setEntity($menu);
|
||||
return $entity_form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setPlugin(PluginInspectionInterface $plugin) {
|
||||
$this->plugin = $plugin;
|
||||
$this->menu = $this->menuStorage->loadOverrideFree($this->plugin->getDerivativeId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the menu has configuration overrides.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the menu has configuration overrides, otherwise FALSE.
|
||||
*/
|
||||
protected function hasMenuOverrides() {
|
||||
// @todo Replace the following with $this->menu->hasOverrides() in https://www.drupal.org/project/drupal/issues/2910353
|
||||
// and remove this function.
|
||||
return $this->configFactory->get($this->menu->getEntityType()
|
||||
->getConfigPrefix() . '.' . $this->menu->id())->hasOverrides();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,6 +7,8 @@ use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Form to select the administration theme.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class ThemeAdminForm extends ConfigFormBase {
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ use Drupal\Core\Theme\ThemeManagerInterface;
|
||||
|
||||
/**
|
||||
* Displays theme configuration for entire site and individual themes.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class ThemeSettingsForm extends ConfigFormBase {
|
||||
|
||||
@@ -212,7 +214,10 @@ class ThemeSettingsForm extends ConfigFormBase {
|
||||
'#type' => 'file',
|
||||
'#title' => t('Upload logo image'),
|
||||
'#maxlength' => 40,
|
||||
'#description' => t("If you don't have direct file access to the server, use this field to upload your logo.")
|
||||
'#description' => t("If you don't have direct file access to the server, use this field to upload your logo."),
|
||||
'#upload_validators' => [
|
||||
'file_validate_is_image' => [],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -252,7 +257,12 @@ class ThemeSettingsForm extends ConfigFormBase {
|
||||
$form['favicon']['settings']['favicon_upload'] = [
|
||||
'#type' => 'file',
|
||||
'#title' => t('Upload favicon image'),
|
||||
'#description' => t("If you don't have direct file access to the server, use this field to upload your shortcut icon.")
|
||||
'#description' => t("If you don't have direct file access to the server, use this field to upload your shortcut icon."),
|
||||
'#upload_validators' => [
|
||||
'file_validate_extensions' => [
|
||||
'ico png gif jpg jpeg apng svg',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -367,37 +377,22 @@ class ThemeSettingsForm extends ConfigFormBase {
|
||||
parent::validateForm($form, $form_state);
|
||||
|
||||
if ($this->moduleHandler->moduleExists('file')) {
|
||||
// Handle file uploads.
|
||||
$validators = ['file_validate_is_image' => []];
|
||||
|
||||
// Check for a new uploaded logo.
|
||||
$file = file_save_upload('logo_upload', $validators, FALSE, 0);
|
||||
if (isset($file)) {
|
||||
// File upload was attempted.
|
||||
if ($file) {
|
||||
// Put the temporary file in form_values so we can save it on submit.
|
||||
$form_state->setValue('logo_upload', $file);
|
||||
}
|
||||
else {
|
||||
// File upload failed.
|
||||
$form_state->setErrorByName('logo_upload', $this->t('The logo could not be uploaded.'));
|
||||
}
|
||||
$file = _file_save_upload_from_form($form['logo']['settings']['logo_upload'], $form_state, 0);
|
||||
if ($file) {
|
||||
// Put the temporary file in form_values so we can save it on submit.
|
||||
$form_state->setValue('logo_upload', $file);
|
||||
}
|
||||
|
||||
$validators = ['file_validate_extensions' => ['ico png gif jpg jpeg apng svg']];
|
||||
|
||||
// Check for a new uploaded favicon.
|
||||
$file = file_save_upload('favicon_upload', $validators, FALSE, 0);
|
||||
if (isset($file)) {
|
||||
// File upload was attempted.
|
||||
if ($file) {
|
||||
// Put the temporary file in form_values so we can save it on submit.
|
||||
$form_state->setValue('favicon_upload', $file);
|
||||
}
|
||||
else {
|
||||
// File upload failed.
|
||||
$form_state->setErrorByName('favicon_upload', $this->t('The favicon could not be uploaded.'));
|
||||
}
|
||||
$file = _file_save_upload_from_form($form['favicon']['settings']['favicon_upload'], $form_state, 0);
|
||||
if ($file) {
|
||||
// Put the temporary file in form_values so we can save it on submit.
|
||||
$form_state->setValue('favicon_upload', $file);
|
||||
}
|
||||
|
||||
// When intending to use the default logo, unset the logo_path.
|
||||
@@ -492,7 +487,7 @@ class ThemeSettingsForm extends ConfigFormBase {
|
||||
*/
|
||||
protected function validatePath($path) {
|
||||
// Absolute local file paths are invalid.
|
||||
if (drupal_realpath($path) == $path) {
|
||||
if (\Drupal::service('file_system')->realpath($path) == $path) {
|
||||
return FALSE;
|
||||
}
|
||||
// A path relative to the Drupal root or a fully qualified URI is valid.
|
||||
|
||||
@@ -15,7 +15,10 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
*
|
||||
* @Block(
|
||||
* id = "system_branding_block",
|
||||
* admin_label = @Translation("Site branding")
|
||||
* admin_label = @Translation("Site branding"),
|
||||
* forms = {
|
||||
* "settings_tray" = "Drupal\system\Form\SystemBrandingOffCanvasForm",
|
||||
* },
|
||||
* )
|
||||
*/
|
||||
class SystemBrandingBlock extends BlockBase implements ContainerFactoryPluginInterface {
|
||||
|
||||
@@ -10,7 +10,10 @@ use Drupal\Core\Block\MainContentBlockPluginInterface;
|
||||
*
|
||||
* @Block(
|
||||
* id = "system_main_block",
|
||||
* admin_label = @Translation("Main page content")
|
||||
* admin_label = @Translation("Main page content"),
|
||||
* forms = {
|
||||
* "settings_tray" = FALSE,
|
||||
* },
|
||||
* )
|
||||
*/
|
||||
class SystemMainBlock extends BlockBase implements MainContentBlockPluginInterface {
|
||||
|
||||
@@ -5,7 +5,6 @@ namespace Drupal\system\Plugin\Block;
|
||||
use Drupal\Core\Block\BlockBase;
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Menu\MenuActiveTrailInterface;
|
||||
use Drupal\Core\Menu\MenuLinkTreeInterface;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
@@ -17,7 +16,10 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
* id = "system_menu_block",
|
||||
* admin_label = @Translation("Menu"),
|
||||
* category = @Translation("Menus"),
|
||||
* deriver = "Drupal\system\Plugin\Derivative\SystemMenuBlock"
|
||||
* deriver = "Drupal\system\Plugin\Derivative\SystemMenuBlock",
|
||||
* forms = {
|
||||
* "settings_tray" = "\Drupal\system\Form\SystemMenuOffCanvasForm",
|
||||
* },
|
||||
* )
|
||||
*/
|
||||
class SystemMenuBlock extends BlockBase implements ContainerFactoryPluginInterface {
|
||||
@@ -29,13 +31,6 @@ class SystemMenuBlock extends BlockBase implements ContainerFactoryPluginInterfa
|
||||
*/
|
||||
protected $menuTree;
|
||||
|
||||
/**
|
||||
* The active menu trail service.
|
||||
*
|
||||
* @var \Drupal\Core\Menu\MenuActiveTrailInterface
|
||||
*/
|
||||
protected $menuActiveTrail;
|
||||
|
||||
/**
|
||||
* Constructs a new SystemMenuBlock.
|
||||
*
|
||||
@@ -47,13 +42,10 @@ class SystemMenuBlock extends BlockBase implements ContainerFactoryPluginInterfa
|
||||
* The plugin implementation definition.
|
||||
* @param \Drupal\Core\Menu\MenuLinkTreeInterface $menu_tree
|
||||
* The menu tree service.
|
||||
* @param \Drupal\Core\Menu\MenuActiveTrailInterface $menu_active_trail
|
||||
* The active menu trail service.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MenuLinkTreeInterface $menu_tree, MenuActiveTrailInterface $menu_active_trail) {
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MenuLinkTreeInterface $menu_tree) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
$this->menuTree = $menu_tree;
|
||||
$this->menuActiveTrail = $menu_active_trail;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,8 +56,7 @@ class SystemMenuBlock extends BlockBase implements ContainerFactoryPluginInterfa
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$container->get('menu.link_tree'),
|
||||
$container->get('menu.active_trail')
|
||||
$container->get('menu.link_tree')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -224,7 +224,7 @@ class GDToolkit extends ImageToolkitBase {
|
||||
$destination = drupal_tempnam('temporary://', 'gd_');
|
||||
}
|
||||
// Convert stream wrapper URI to normal path.
|
||||
$destination = drupal_realpath($destination);
|
||||
$destination = \Drupal::service('file_system')->realpath($destination);
|
||||
}
|
||||
|
||||
$function = 'image' . image_type_to_extension($this->getType(), FALSE);
|
||||
|
||||
@@ -2,506 +2,20 @@
|
||||
|
||||
namespace Drupal\system\Plugin\views\field;
|
||||
|
||||
use Drupal\Core\Cache\CacheableDependencyInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\RevisionableInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Language\LanguageManagerInterface;
|
||||
use Drupal\Core\Routing\RedirectDestinationTrait;
|
||||
use Drupal\Core\TypedData\TranslatableInterface;
|
||||
use Drupal\views\Entity\Render\EntityTranslationRenderTrait;
|
||||
use Drupal\views\Plugin\views\display\DisplayPluginBase;
|
||||
use Drupal\views\Plugin\views\field\FieldPluginBase;
|
||||
use Drupal\views\Plugin\views\field\UncacheableFieldHandlerTrait;
|
||||
use Drupal\views\Plugin\views\style\Table;
|
||||
use Drupal\views\ResultRow;
|
||||
use Drupal\views\ViewExecutable;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
@trigger_error(__NAMESPACE__ . '\BulkForm is deprecated in Drupal 8.5.x, will be removed before Drupal 9.0.0. Use \Drupal\views\Plugin\views\field\BulkForm instead. See https://www.drupal.org/node/2916716.', E_USER_DEPRECATED);
|
||||
|
||||
use Drupal\views\Plugin\views\field\BulkForm as ViewsBulkForm;
|
||||
|
||||
/**
|
||||
* Defines a actions-based bulk operation form element.
|
||||
*
|
||||
* @ViewsField("bulk_form")
|
||||
* @ViewsField("legacy_bulk_form")
|
||||
*
|
||||
* @deprecated in Drupal 8.5.x, will be removed before Drupal 9.0.0. Use
|
||||
* \Drupal\views\Plugin\views\field\BulkForm instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2916716
|
||||
*/
|
||||
class BulkForm extends FieldPluginBase implements CacheableDependencyInterface {
|
||||
|
||||
use RedirectDestinationTrait;
|
||||
use UncacheableFieldHandlerTrait;
|
||||
use EntityTranslationRenderTrait;
|
||||
|
||||
/**
|
||||
* The entity manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* The action storage.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityStorageInterface
|
||||
*/
|
||||
protected $actionStorage;
|
||||
|
||||
/**
|
||||
* An array of actions that can be executed.
|
||||
*
|
||||
* @var \Drupal\system\ActionConfigEntityInterface[]
|
||||
*/
|
||||
protected $actions = [];
|
||||
|
||||
/**
|
||||
* The language manager.
|
||||
*
|
||||
* @var \Drupal\Core\Language\LanguageManagerInterface
|
||||
*/
|
||||
protected $languageManager;
|
||||
|
||||
/**
|
||||
* Constructs a new BulkForm object.
|
||||
*
|
||||
* @param array $configuration
|
||||
* A configuration array containing information about the plugin instance.
|
||||
* @param string $plugin_id
|
||||
* The plugin ID for the plugin instance.
|
||||
* @param mixed $plugin_definition
|
||||
* The plugin implementation definition.
|
||||
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
|
||||
* The entity manager.
|
||||
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
|
||||
* The language manager.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
|
||||
$this->entityManager = $entity_manager;
|
||||
$this->actionStorage = $entity_manager->getStorage('action');
|
||||
$this->languageManager = $language_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$container->get('entity.manager'),
|
||||
$container->get('language_manager')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
|
||||
parent::init($view, $display, $options);
|
||||
|
||||
$entity_type = $this->getEntityType();
|
||||
// Filter the actions to only include those for this entity type.
|
||||
$this->actions = array_filter($this->actionStorage->loadMultiple(), function ($action) use ($entity_type) {
|
||||
return $action->getType() == $entity_type;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCacheMaxAge() {
|
||||
// @todo Consider making the bulk operation form cacheable. See
|
||||
// https://www.drupal.org/node/2503009.
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCacheContexts() {
|
||||
return $this->languageManager->isMultilingual() ? $this->getEntityTranslationRenderer()->getCacheContexts() : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCacheTags() {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getEntityTypeId() {
|
||||
return $this->getEntityType();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getEntityManager() {
|
||||
return $this->entityManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getLanguageManager() {
|
||||
return $this->languageManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getView() {
|
||||
return $this->view;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function defineOptions() {
|
||||
$options = parent::defineOptions();
|
||||
$options['action_title'] = ['default' => $this->t('Action')];
|
||||
$options['include_exclude'] = [
|
||||
'default' => 'exclude',
|
||||
];
|
||||
$options['selected_actions'] = [
|
||||
'default' => [],
|
||||
];
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
|
||||
$form['action_title'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Action title'),
|
||||
'#default_value' => $this->options['action_title'],
|
||||
'#description' => $this->t('The title shown above the actions dropdown.'),
|
||||
];
|
||||
|
||||
$form['include_exclude'] = [
|
||||
'#type' => 'radios',
|
||||
'#title' => $this->t('Available actions'),
|
||||
'#options' => [
|
||||
'exclude' => $this->t('All actions, except selected'),
|
||||
'include' => $this->t('Only selected actions'),
|
||||
],
|
||||
'#default_value' => $this->options['include_exclude'],
|
||||
];
|
||||
$form['selected_actions'] = [
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => $this->t('Selected actions'),
|
||||
'#options' => $this->getBulkOptions(FALSE),
|
||||
'#default_value' => $this->options['selected_actions'],
|
||||
];
|
||||
|
||||
parent::buildOptionsForm($form, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validateOptionsForm(&$form, FormStateInterface $form_state) {
|
||||
parent::validateOptionsForm($form, $form_state);
|
||||
|
||||
$selected_actions = $form_state->getValue(['options', 'selected_actions']);
|
||||
$form_state->setValue(['options', 'selected_actions'], array_values(array_filter($selected_actions)));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function preRender(&$values) {
|
||||
parent::preRender($values);
|
||||
|
||||
// If the view is using a table style, provide a placeholder for a
|
||||
// "select all" checkbox.
|
||||
if (!empty($this->view->style_plugin) && $this->view->style_plugin instanceof Table) {
|
||||
// Add the tableselect css classes.
|
||||
$this->options['element_label_class'] .= 'select-all';
|
||||
// Hide the actual label of the field on the table header.
|
||||
$this->options['label'] = '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getValue(ResultRow $row, $field = NULL) {
|
||||
return '<!--form-item-' . $this->options['id'] . '--' . $row->index . '-->';
|
||||
}
|
||||
|
||||
/**
|
||||
* Form constructor for the bulk form.
|
||||
*
|
||||
* @param array $form
|
||||
* An associative array containing the structure of the form.
|
||||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
* The current state of the form.
|
||||
*/
|
||||
public function viewsForm(&$form, FormStateInterface $form_state) {
|
||||
// Make sure we do not accidentally cache this form.
|
||||
// @todo Evaluate this again in https://www.drupal.org/node/2503009.
|
||||
$form['#cache']['max-age'] = 0;
|
||||
|
||||
// Add the tableselect javascript.
|
||||
$form['#attached']['library'][] = 'core/drupal.tableselect';
|
||||
$use_revision = array_key_exists('revision', $this->view->getQuery()->getEntityTableInfo());
|
||||
|
||||
// Only add the bulk form options and buttons if there are results.
|
||||
if (!empty($this->view->result)) {
|
||||
// Render checkboxes for all rows.
|
||||
$form[$this->options['id']]['#tree'] = TRUE;
|
||||
foreach ($this->view->result as $row_index => $row) {
|
||||
$entity = $this->getEntityTranslation($this->getEntity($row), $row);
|
||||
|
||||
$form[$this->options['id']][$row_index] = [
|
||||
'#type' => 'checkbox',
|
||||
// We are not able to determine a main "title" for each row, so we can
|
||||
// only output a generic label.
|
||||
'#title' => $this->t('Update this item'),
|
||||
'#title_display' => 'invisible',
|
||||
'#default_value' => !empty($form_state->getValue($this->options['id'])[$row_index]) ? 1 : NULL,
|
||||
'#return_value' => $this->calculateEntityBulkFormKey($entity, $use_revision),
|
||||
];
|
||||
}
|
||||
|
||||
// Replace the form submit button label.
|
||||
$form['actions']['submit']['#value'] = $this->t('Apply to selected items');
|
||||
|
||||
// Ensure a consistent container for filters/operations in the view header.
|
||||
$form['header'] = [
|
||||
'#type' => 'container',
|
||||
'#weight' => -100,
|
||||
];
|
||||
|
||||
// Build the bulk operations action widget for the header.
|
||||
// Allow themes to apply .container-inline on this separate container.
|
||||
$form['header'][$this->options['id']] = [
|
||||
'#type' => 'container',
|
||||
];
|
||||
$form['header'][$this->options['id']]['action'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->options['action_title'],
|
||||
'#options' => $this->getBulkOptions(),
|
||||
];
|
||||
|
||||
// Duplicate the form actions into the action container in the header.
|
||||
$form['header'][$this->options['id']]['actions'] = $form['actions'];
|
||||
}
|
||||
else {
|
||||
// Remove the default actions build array.
|
||||
unset($form['actions']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the available operations for this form.
|
||||
*
|
||||
* @param bool $filtered
|
||||
* (optional) Whether to filter actions to selected actions.
|
||||
* @return array
|
||||
* An associative array of operations, suitable for a select element.
|
||||
*/
|
||||
protected function getBulkOptions($filtered = TRUE) {
|
||||
$options = [];
|
||||
// Filter the action list.
|
||||
foreach ($this->actions as $id => $action) {
|
||||
if ($filtered) {
|
||||
$in_selected = in_array($id, $this->options['selected_actions']);
|
||||
// If the field is configured to include only the selected actions,
|
||||
// skip actions that were not selected.
|
||||
if (($this->options['include_exclude'] == 'include') && !$in_selected) {
|
||||
continue;
|
||||
}
|
||||
// Otherwise, if the field is configured to exclude the selected
|
||||
// actions, skip actions that were selected.
|
||||
elseif (($this->options['include_exclude'] == 'exclude') && $in_selected) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$options[$id] = $action->label();
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit handler for the bulk form.
|
||||
*
|
||||
* @param array $form
|
||||
* An associative array containing the structure of the form.
|
||||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
* The current state of the form.
|
||||
*
|
||||
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
|
||||
* Thrown when the user tried to access an action without access to it.
|
||||
*/
|
||||
public function viewsFormSubmit(&$form, FormStateInterface $form_state) {
|
||||
if ($form_state->get('step') == 'views_form_views_form') {
|
||||
// Filter only selected checkboxes. Use the actual user input rather than
|
||||
// the raw form values array, since the site data may change before the
|
||||
// bulk form is submitted, which can lead to data loss.
|
||||
$user_input = $form_state->getUserInput();
|
||||
$selected = array_filter($user_input[$this->options['id']]);
|
||||
$entities = [];
|
||||
$action = $this->actions[$form_state->getValue('action')];
|
||||
$count = 0;
|
||||
|
||||
foreach ($selected as $bulk_form_key) {
|
||||
$entity = $this->loadEntityFromBulkFormKey($bulk_form_key);
|
||||
|
||||
// Skip execution if the user did not have access.
|
||||
if (!$action->getPlugin()->access($entity, $this->view->getUser())) {
|
||||
$this->drupalSetMessage($this->t('No access to execute %action on the @entity_type_label %entity_label.', [
|
||||
'%action' => $action->label(),
|
||||
'@entity_type_label' => $entity->getEntityType()->getLabel(),
|
||||
'%entity_label' => $entity->label()
|
||||
]), 'error');
|
||||
continue;
|
||||
}
|
||||
|
||||
$count++;
|
||||
|
||||
$entities[$bulk_form_key] = $entity;
|
||||
}
|
||||
|
||||
$action->execute($entities);
|
||||
|
||||
$operation_definition = $action->getPluginDefinition();
|
||||
if (!empty($operation_definition['confirm_form_route_name'])) {
|
||||
$options = [
|
||||
'query' => $this->getDestinationArray(),
|
||||
];
|
||||
$form_state->setRedirect($operation_definition['confirm_form_route_name'], [], $options);
|
||||
}
|
||||
else {
|
||||
// Don't display the message unless there are some elements affected and
|
||||
// there is no confirmation form.
|
||||
if ($count) {
|
||||
drupal_set_message($this->formatPlural($count, '%action was applied to @count item.', '%action was applied to @count items.', [
|
||||
'%action' => $action->label(),
|
||||
]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the message to be displayed when there are no selected items.
|
||||
*
|
||||
* @return string
|
||||
* Message displayed when no items are selected.
|
||||
*/
|
||||
protected function emptySelectedMessage() {
|
||||
return $this->t('No items selected.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function viewsFormValidate(&$form, FormStateInterface $form_state) {
|
||||
$selected = array_filter($form_state->getValue($this->options['id']));
|
||||
if (empty($selected)) {
|
||||
$form_state->setErrorByName('', $this->emptySelectedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
if ($this->languageManager->isMultilingual()) {
|
||||
$this->getEntityTranslationRenderer()->query($this->query, $this->relationship);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function clickSortable() {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps drupal_set_message().
|
||||
*/
|
||||
protected function drupalSetMessage($message = NULL, $type = 'status', $repeat = FALSE) {
|
||||
drupal_set_message($message, $type, $repeat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates a bulk form key.
|
||||
*
|
||||
* This generates a key that is used as the checkbox return value when
|
||||
* submitting a bulk form. This key allows the entity for the row to be loaded
|
||||
* totally independently of the executed view row.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityInterface $entity
|
||||
* The entity to calculate a bulk form key for.
|
||||
* @param bool $use_revision
|
||||
* Whether the revision id should be added to the bulk form key. This should
|
||||
* be set to TRUE only if the view is listing entity revisions.
|
||||
*
|
||||
* @return string
|
||||
* The bulk form key representing the entity's id, language and revision (if
|
||||
* applicable) as one string.
|
||||
*
|
||||
* @see self::loadEntityFromBulkFormKey()
|
||||
*/
|
||||
protected function calculateEntityBulkFormKey(EntityInterface $entity, $use_revision) {
|
||||
$key_parts = [$entity->language()->getId(), $entity->id()];
|
||||
|
||||
if ($entity instanceof RevisionableInterface && $use_revision) {
|
||||
$key_parts[] = $entity->getRevisionId();
|
||||
}
|
||||
|
||||
// An entity ID could be an arbitrary string (although they are typically
|
||||
// numeric). JSON then Base64 encoding ensures the bulk_form_key is
|
||||
// safe to use in HTML, and that the key parts can be retrieved.
|
||||
$key = json_encode($key_parts);
|
||||
return base64_encode($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads an entity based on a bulk form key.
|
||||
*
|
||||
* @param string $bulk_form_key
|
||||
* The bulk form key representing the entity's id, language and revision (if
|
||||
* applicable) as one string.
|
||||
*
|
||||
* @return \Drupal\Core\Entity\EntityInterface
|
||||
* The entity loaded in the state (language, optionally revision) specified
|
||||
* as part of the bulk form key.
|
||||
*/
|
||||
protected function loadEntityFromBulkFormKey($bulk_form_key) {
|
||||
$key = base64_decode($bulk_form_key);
|
||||
$key_parts = json_decode($key);
|
||||
$revision_id = NULL;
|
||||
|
||||
// If there are 3 items, vid will be last.
|
||||
if (count($key_parts) === 3) {
|
||||
$revision_id = array_pop($key_parts);
|
||||
}
|
||||
|
||||
// The first two items will always be langcode and ID.
|
||||
$id = array_pop($key_parts);
|
||||
$langcode = array_pop($key_parts);
|
||||
|
||||
// Load the entity or a specific revision depending on the given key.
|
||||
$storage = $this->entityManager->getStorage($this->getEntityType());
|
||||
$entity = $revision_id ? $storage->loadRevision($revision_id) : $storage->load($id);
|
||||
|
||||
if ($entity instanceof TranslatableInterface) {
|
||||
$entity = $entity->getTranslation($langcode);
|
||||
}
|
||||
|
||||
return $entity;
|
||||
}
|
||||
class BulkForm extends ViewsBulkForm {
|
||||
|
||||
}
|
||||
|
||||
@@ -111,12 +111,19 @@ trait EntityDefinitionTestTrait {
|
||||
*
|
||||
* @param string $type
|
||||
* (optional) The field type for the new field. Defaults to 'string'.
|
||||
* @param string $entity_type_id
|
||||
* (optional) The entity type ID the base field should be attached to.
|
||||
* Defaults to 'entity_test_update'.
|
||||
* @param bool $is_revisionable
|
||||
* (optional) If the base field should be revisionable or not. Defaults to
|
||||
* FALSE.
|
||||
*/
|
||||
protected function addBaseField($type = 'string') {
|
||||
protected function addBaseField($type = 'string', $entity_type_id = 'entity_test_update', $is_revisionable = FALSE) {
|
||||
$definitions['new_base_field'] = BaseFieldDefinition::create($type)
|
||||
->setName('new_base_field')
|
||||
->setRevisionable($is_revisionable)
|
||||
->setLabel(t('A new base field'));
|
||||
$this->state->set('entity_test_update.additional_base_field_definitions', $definitions);
|
||||
$this->state->set($entity_type_id . '.additional_base_field_definitions', $definitions);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,9 +174,12 @@ trait EntityDefinitionTestTrait {
|
||||
|
||||
/**
|
||||
* Removes the new base field from the 'entity_test_update' entity type.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* (optional) The entity type ID the base field should be attached to.
|
||||
*/
|
||||
protected function removeBaseField() {
|
||||
$this->state->delete('entity_test_update.additional_base_field_definitions');
|
||||
protected function removeBaseField($entity_type_id = 'entity_test_update') {
|
||||
$this->state->delete($entity_type_id . '.additional_base_field_definitions');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+22
-14
@@ -64,6 +64,27 @@ class DistributionProfileTranslationQueryTest extends InstallerTestBase {
|
||||
// The unrouted URL assembler does not exist at this point, so we build the
|
||||
// URL ourselves.
|
||||
$this->drupalGet($GLOBALS['base_url'] . '/core/install.php' . '?langcode=fr');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUpLanguage() {
|
||||
// This step is skipped, because the distribution profile uses a fixed
|
||||
// language.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUpProfile() {
|
||||
// This step is skipped, because there is a distribution profile.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUpSettings() {
|
||||
// The language should have been automatically detected, all following
|
||||
// screens should be translated already.
|
||||
$elements = $this->xpath('//input[@type="submit"]/@value');
|
||||
@@ -80,21 +101,8 @@ class DistributionProfileTranslationQueryTest extends InstallerTestBase {
|
||||
$this->assertRaw($this->info['distribution']['install']['theme']);
|
||||
// Verify that the "Choose profile" step does not appear.
|
||||
$this->assertNoText('profile');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUpLanguage() {
|
||||
// This step is skipped, because the distribution profile uses a fixed
|
||||
// language.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUpProfile() {
|
||||
// This step is skipped, because there is a distribution profile.
|
||||
parent::setUpSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -59,23 +59,6 @@ class DistributionProfileTranslationTest extends InstallerTestBase {
|
||||
file_put_contents(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.de.po', $this->getPo('de'));
|
||||
|
||||
parent::visitInstaller();
|
||||
|
||||
// The language should have been automatically detected, all following
|
||||
// screens should be translated already.
|
||||
$elements = $this->xpath('//input[@type="submit"]/@value');
|
||||
$this->assertEqual((string) current($elements), 'Save and continue de');
|
||||
$this->translations['Save and continue'] = 'Save and continue de';
|
||||
|
||||
// Check the language direction.
|
||||
$direction = (string) current($this->xpath('/html/@dir'));
|
||||
$this->assertEqual($direction, 'ltr');
|
||||
|
||||
// Verify that the distribution name appears.
|
||||
$this->assertRaw($this->info['distribution']['name']);
|
||||
// Verify that the requested theme is used.
|
||||
$this->assertRaw($this->info['distribution']['install']['theme']);
|
||||
// Verify that the "Choose profile" step does not appear.
|
||||
$this->assertNoText('profile');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,6 +76,31 @@ class DistributionProfileTranslationTest extends InstallerTestBase {
|
||||
// This step is skipped, because there is a distribution profile.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUpSettings() {
|
||||
// The language should have been automatically detected, all following
|
||||
// screens should be translated already.
|
||||
$elements = $this->xpath('//input[@type="submit"]/@value');
|
||||
$this->assertEqual((string) current($elements), 'Save and continue de');
|
||||
$this->translations['Save and continue'] = 'Save and continue de';
|
||||
|
||||
// Check the language direction.
|
||||
$direction = (string) current($this->xpath('/html/@dir'));
|
||||
$this->assertEqual($direction, 'ltr');
|
||||
|
||||
// Verify that the distribution name appears.
|
||||
$this->assertRaw($this->info['distribution']['name']);
|
||||
// Verify that the requested theme is used.
|
||||
$this->assertRaw($this->info['distribution']['install']['theme']);
|
||||
// Verify that the "Choose profile" step does not appear.
|
||||
$this->assertNoText('profile');
|
||||
|
||||
parent::setUpSettings();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Confirms that the installation succeeded.
|
||||
*/
|
||||
|
||||
@@ -32,6 +32,7 @@ class InstallerExistingInstallationTest extends InstallerTestBase {
|
||||
$this->visitInstaller();
|
||||
$this->setUpLanguage();
|
||||
$this->setUpProfile();
|
||||
$this->setUpRequirementsProblem();
|
||||
$this->setUpSettings();
|
||||
$this->assertRaw('Drupal already installed');
|
||||
}
|
||||
|
||||
@@ -21,25 +21,20 @@ class SingleVisibleProfileTest extends InstallerTestBase {
|
||||
*/
|
||||
protected $profile = NULL;
|
||||
|
||||
/**
|
||||
* The install profile info.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $info;
|
||||
|
||||
protected function setUp() {
|
||||
$this->info = [
|
||||
'type' => 'profile',
|
||||
'core' => \Drupal::CORE_COMPATIBILITY,
|
||||
'name' => 'Override standard',
|
||||
'hidden' => TRUE,
|
||||
];
|
||||
// File API functions are not available yet.
|
||||
$path = $this->siteDirectory . '/profiles/standard';
|
||||
mkdir($path, 0777, TRUE);
|
||||
file_put_contents("$path/standard.info.yml", Yaml::encode($this->info));
|
||||
|
||||
$profiles = ['standard', 'demo_umami'];
|
||||
foreach ($profiles as $profile) {
|
||||
$info = [
|
||||
'type' => 'profile',
|
||||
'core' => \Drupal::CORE_COMPATIBILITY,
|
||||
'name' => 'Override ' . $profile,
|
||||
'hidden' => TRUE,
|
||||
];
|
||||
// File API functions are not available yet.
|
||||
$path = $this->siteDirectory . '/profiles/' . $profile;
|
||||
mkdir($path, 0777, TRUE);
|
||||
file_put_contents("$path/$profile.info.yml", Yaml::encode($info));
|
||||
}
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
|
||||
@@ -18,11 +18,8 @@ class StandardInstallerTest extends ConfigAfterInstallerTestBase {
|
||||
* Ensures that the user page is available after installation.
|
||||
*/
|
||||
public function testInstaller() {
|
||||
// Verify that the confirmation message appears.
|
||||
require_once \Drupal::root() . '/core/includes/install.inc';
|
||||
$this->assertRaw(t('Congratulations, you installed @drupal!', [
|
||||
'@drupal' => drupal_install_profile_distribution_name(),
|
||||
]));
|
||||
// Verify that the Standard install profile's default frontpage appears.
|
||||
$this->assertRaw('No front page content has been created yet.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -65,7 +65,7 @@ class FrontPageTest extends WebTestBase {
|
||||
// Change the front page to an invalid path.
|
||||
$edit = ['site_frontpage' => '/kittens'];
|
||||
$this->drupalPostForm('admin/config/system/site-information', $edit, t('Save configuration'));
|
||||
$this->assertText(t("The path '@path' is either invalid or you do not have access to it.", ['@path' => $edit['site_frontpage']]));
|
||||
$this->assertText(t("Either the path '@path' is invalid or you do not have access to it.", ['@path' => $edit['site_frontpage']]));
|
||||
|
||||
// Change the front page to a path without a starting slash.
|
||||
$edit = ['site_frontpage' => $this->nodePath];
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\system\Tests\System;
|
||||
|
||||
use Drupal\rest\Tests\RESTTestBase;
|
||||
|
||||
/**
|
||||
* Tests to see if generator header is added.
|
||||
*
|
||||
* @group system
|
||||
*/
|
||||
class ResponseGeneratorTest extends RESTTestBase {
|
||||
|
||||
/**
|
||||
* Modules to install.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['hal', 'rest', 'node', 'basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
|
||||
$permissions = $this->entityPermissions('node', 'view');
|
||||
$account = $this->drupalCreateUser($permissions);
|
||||
$this->drupalLogin($account);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to see if generator header is added.
|
||||
*/
|
||||
public function testGeneratorHeaderAdded() {
|
||||
|
||||
$node = $this->drupalCreateNode();
|
||||
|
||||
list($version) = explode('.', \Drupal::VERSION, 2);
|
||||
$expectedGeneratorHeader = 'Drupal ' . $version . ' (https://www.drupal.org)';
|
||||
|
||||
// Check to see if the header is added when viewing a normal content page
|
||||
$this->drupalGet($node->urlInfo());
|
||||
$this->assertResponse(200);
|
||||
$this->assertEqual('text/html; charset=UTF-8', $this->drupalGetHeader('Content-Type'));
|
||||
$this->assertEqual($expectedGeneratorHeader, $this->drupalGetHeader('X-Generator'));
|
||||
|
||||
// Check to see if the header is also added for a non-successful response
|
||||
$this->drupalGet('llama');
|
||||
$this->assertResponse(404);
|
||||
$this->assertEqual('text/html; charset=UTF-8', $this->drupalGetHeader('Content-Type'));
|
||||
$this->assertEqual($expectedGeneratorHeader, $this->drupalGetHeader('X-Generator'));
|
||||
|
||||
// Enable cookie-based authentication for the entity:node REST resource.
|
||||
/** @var \Drupal\rest\RestResourceConfigInterface $resource_config */
|
||||
$resource_config = $this->resourceConfigStorage->load('entity.node');
|
||||
$configuration = $resource_config->get('configuration');
|
||||
$configuration['authentication'][] = 'cookie';
|
||||
$resource_config->set('configuration', $configuration)->save();
|
||||
$this->rebuildCache();
|
||||
|
||||
// Tests to see if this also works for a non-html request
|
||||
$this->httpRequest($node->urlInfo()->setOption('query', ['_format' => 'hal_json']), 'GET');
|
||||
$this->assertResponse(200);
|
||||
$this->assertEqual('application/hal+json', $this->drupalGetHeader('Content-Type'));
|
||||
$this->assertEqual($expectedGeneratorHeader, $this->drupalGetHeader('X-Generator'));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -152,7 +152,7 @@ class ThemeTest extends WebTestBase {
|
||||
// Semi-absolute path to arbitrary non-existing file.
|
||||
'/core/misc/whatever.png',
|
||||
// Absolute paths to any local file (even if it exists).
|
||||
drupal_realpath($file->uri),
|
||||
\Drupal::service('file_system')->realpath($file->uri),
|
||||
];
|
||||
$this->drupalGet('admin/appearance/settings');
|
||||
foreach ($unsupported_paths as $path) {
|
||||
@@ -168,7 +168,7 @@ class ThemeTest extends WebTestBase {
|
||||
$edit = [
|
||||
'default_logo' => FALSE,
|
||||
'logo_path' => '',
|
||||
'files[logo_upload]' => drupal_realpath($file->uri),
|
||||
'files[logo_upload]' => \Drupal::service('file_system')->realpath($file->uri),
|
||||
];
|
||||
$this->drupalPostForm('admin/appearance/settings', $edit, t('Save configuration'));
|
||||
|
||||
@@ -390,7 +390,7 @@ class ThemeTest extends WebTestBase {
|
||||
// Check that bartik can be uninstalled now.
|
||||
$this->assertRaw('Uninstall Bartik theme', 'A link to uninstall the Bartik theme does appear on the theme settings page.');
|
||||
|
||||
// Check that the classy theme still can't be uninstalled as neither of it's
|
||||
// Check that the classy theme still can't be uninstalled as neither of its
|
||||
// base themes have been.
|
||||
$this->assertNoRaw('Uninstall Classy theme', 'A link to uninstall the Classy theme does not appear on the theme settings page.');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user