diff --git a/core/includes/menu.inc b/core/includes/menu.inc index d205ac0..ccc40f8 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -895,7 +895,6 @@ function _menu_link_translate(&$item, $translate = FALSE) { // current path, and we can take over the argument map for a link like // 'foo/%/bar'. This inheritance is only valid for breadcrumb links. // @see _menu_tree_check_access() - // @see menu_get_active_breadcrumb() elseif ($translate && ($current_router_item = menu_get_item())) { // If $translate is TRUE, then this link is in the active trail. // Only translate paths within the current path. @@ -2610,57 +2609,6 @@ function menu_get_active_trail() { } /** - * Gets the breadcrumb for the current page, as determined by the active trail. - * - * @see menu_set_active_trail() - */ -function menu_get_active_breadcrumb() { - $breadcrumb = array(); - - // No breadcrumb for the front page. - if (drupal_is_front_page()) { - return $breadcrumb; - } - - $item = menu_get_item(); - if (!empty($item['access'])) { - $active_trail = menu_get_active_trail(); - - // Allow modules to alter the breadcrumb, if possible, as that is much - // faster than rebuilding an entirely new active trail. - drupal_alter('menu_breadcrumb', $active_trail, $item); - - // Don't show a link to the current page in the breadcrumb trail. - $end = end($active_trail); - if (Drupal::request()->attributes->get('_system_path') == $end['href']) { - array_pop($active_trail); - } - - // Remove the tab root (parent) if the current path links to its parent. - // Normally, the tab root link is included in the breadcrumb, as soon as we - // are on a local task or any other child link. However, if we are on a - // default local task (e.g., node/%/view), then we do not want the tab root - // link (e.g., node/%) to appear, as it would be identical to the current - // page. Since this behavior also needs to work recursively (i.e., on - // default local tasks of default local tasks), and since the last non-task - // link in the trail is used as page title (see menu_get_active_title()), - // this condition cannot be cleanly integrated into menu_get_active_trail(). - // menu_get_active_trail() already skips all links that link to their parent - // (commonly MENU_DEFAULT_LOCAL_TASK). In order to also hide the parent link - // itself, we always remove the last link in the trail, if the current - // router item links to its parent. - if (($item['type'] & MENU_LINKS_TO_PARENT) == MENU_LINKS_TO_PARENT) { - array_pop($active_trail); - } - - foreach ($active_trail as $parent) { - $breadcrumb[] = l($parent['title'], $parent['href'], $parent['localized_options']); - } - } - return $breadcrumb; -} - -/** * Gets the title of the current page, as determined by the active trail. */ function menu_get_active_title() { diff --git a/core/lib/Drupal/Core/Config/Entity/DraggableListController.php b/core/lib/Drupal/Core/Config/Entity/DraggableListController.php deleted file mode 100644 index 5370be5..0000000 --- a/core/lib/Drupal/Core/Config/Entity/DraggableListController.php +++ /dev/null @@ -1,147 +0,0 @@ -entityInfo['entity_keys']['weight'])) { - $this->weightKey = $this->entityInfo['entity_keys']['weight']; - } - } - - /** - * {@inheritdoc} - */ - public function buildHeader() { - $header = array(); - if (!empty($this->weightKey)) { - $header['weight'] = t('Weight'); - } - return $header + parent::buildHeader(); - } - - /** - * {@inheritdoc} - */ - public function buildRow(EntityInterface $entity) { - $row = array(); - if (!empty($this->weightKey)) { - // Override default values to markup elements. - $row['#attributes']['class'][] = 'draggable'; - $row['#weight'] = $entity->get($this->weightKey); - // Add weight column. - $row['weight'] = array( - '#type' => 'weight', - '#title' => t('Weight for @title', array('@title' => $entity->label())), - '#title_display' => 'invisible', - '#default_value' => $entity->get($this->weightKey), - '#attributes' => array('class' => array('weight')), - ); - } - return $row + parent::buildRow($entity); - } - - /** - * {@inheritdoc} - */ - public function render() { - if (!empty($this->weightKey)) { - return drupal_get_form($this); - } - return parent::render(); - } - - /** - * {@inheritdoc} - */ - public function buildForm(array $form, array &$form_state) { - $form[$this->entitiesKey] = array( - '#type' => 'table', - '#header' => $this->buildHeader(), - '#empty' => t('There is no @label yet.', array('@label' => $this->entityInfo['label'])), - '#tabledrag' => array( - array('order', 'sibling', 'weight'), - ), - ); - - $this->entities = $this->load(); - foreach ($this->entities as $entity) { - $row = $this->buildRow($entity); - if (isset($row['label'])) { - $row['label'] = array('#markup' => $row['label']); - } - $form[$this->entitiesKey][$entity->id()] = $row; - } - - $form['actions']['#type'] = 'actions'; - $form['actions']['submit'] = array( - '#type' => 'submit', - '#value' => t('Save order'), - '#button_type' => 'primary', - ); - - return $form; - } - - /** - * {@inheritdoc} - */ - public function validateForm(array &$form, array &$form_state) { - // No validation. - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, array &$form_state) { - foreach ($form_state['values'][$this->entitiesKey] as $id => $value) { - if (isset($this->entities[$id]) && $this->entities[$id]->get($this->weightKey) != $value['weight']) { - // Save entity only when its weight was changed. - $this->entities[$id]->set($this->weightKey, $value['weight']); - $this->entities[$id]->save(); - } - } - } - -} diff --git a/core/modules/action/lib/Drupal/action/ActionFormControllerBase.php b/core/modules/action/lib/Drupal/action/ActionFormControllerBase.php index 4f50ce3..7c0e86d 100644 --- a/core/modules/action/lib/Drupal/action/ActionFormControllerBase.php +++ b/core/modules/action/lib/Drupal/action/ActionFormControllerBase.php @@ -64,19 +64,19 @@ public function buildForm(array $form, array &$form_state) { public function form(array $form, array &$form_state) { $form['label'] = array( '#type' => 'textfield', - '#title' => $this->t('Label'), + '#title' => t('Label'), '#default_value' => $this->entity->label(), '#maxlength' => '255', - '#description' => $this->t('A unique label for this advanced action. This label will be displayed in the interface of modules that integrate with actions.'), + '#description' => t('A unique label for this advanced action. This label will be displayed in the interface of modules that integrate with actions.'), ); $form['id'] = array( '#type' => 'machine_name', - '#title' => $this->t('Machine name'), + '#title' => t('Machine name'), '#default_value' => $this->entity->id(), '#disabled' => !$this->entity->isNew(), '#maxlength' => 64, - '#description' => $this->t('A unique name for this action. It must only contain lowercase letters, numbers and underscores.'), + '#description' => t('A unique name for this action. It must only contain lowercase letters, numbers and underscores.'), '#machine_name' => array( 'exists' => array($this, 'exists'), ), @@ -148,7 +148,7 @@ public function submit(array $form, array &$form_state) { */ public function save(array $form, array &$form_state) { $this->entity->save(); - drupal_set_message($this->t('The action has been successfully saved.')); + drupal_set_message(t('The action has been successfully saved.')); $form_state['redirect'] = 'admin/config/system/actions'; } diff --git a/core/modules/action/lib/Drupal/action/Form/ActionAdminManageForm.php b/core/modules/action/lib/Drupal/action/Form/ActionAdminManageForm.php index 3b221db..d825415 100644 --- a/core/modules/action/lib/Drupal/action/Form/ActionAdminManageForm.php +++ b/core/modules/action/lib/Drupal/action/Form/ActionAdminManageForm.php @@ -7,7 +7,8 @@ namespace Drupal\action\Form; -use Drupal\Core\Form\FormBase; +use Drupal\Core\Controller\ControllerInterface; +use Drupal\Core\Form\FormInterface; use Drupal\Component\Utility\Crypt; use Drupal\Core\Action\ActionManager; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -15,7 +16,7 @@ /** * Provides a configuration form for configurable actions. */ -class ActionAdminManageForm extends FormBase { +class ActionAdminManageForm implements FormInterface, ControllerInterface { /** * The action plugin manager. @@ -63,22 +64,22 @@ public function buildForm(array $form, array &$form_state) { } $form['parent'] = array( '#type' => 'details', - '#title' => $this->t('Create an advanced action'), + '#title' => t('Create an advanced action'), '#attributes' => array('class' => array('container-inline')), ); $form['parent']['action'] = array( '#type' => 'select', - '#title' => $this->t('Action'), + '#title' => t('Action'), '#title_display' => 'invisible', '#options' => $actions, - '#empty_option' => $this->t('Choose an advanced action'), + '#empty_option' => t('Choose an advanced action'), ); $form['parent']['actions'] = array( '#type' => 'actions' ); $form['parent']['actions']['submit'] = array( '#type' => 'submit', - '#value' => $this->t('Create'), + '#value' => t('Create'), ); return $form; } @@ -86,6 +87,12 @@ public function buildForm(array $form, array &$form_state) { /** * {@inheritdoc} */ + public function validateForm(array &$form, array &$form_state) { + } + + /** + * {@inheritdoc} + */ public function submitForm(array &$form, array &$form_state) { if ($form_state['values']['action']) { $form_state['redirect'] = 'admin/config/system/actions/add/' . $form_state['values']['action']; diff --git a/core/modules/action/lib/Drupal/action/Form/ActionDeleteForm.php b/core/modules/action/lib/Drupal/action/Form/ActionDeleteForm.php index 45c8649..0f304af 100644 --- a/core/modules/action/lib/Drupal/action/Form/ActionDeleteForm.php +++ b/core/modules/action/lib/Drupal/action/Form/ActionDeleteForm.php @@ -18,14 +18,14 @@ class ActionDeleteForm extends EntityConfirmFormBase { * {@inheritdoc} */ public function getQuestion() { - return $this->t('Are you sure you want to delete the action %action?', array('%action' => $this->entity->label())); + return t('Are you sure you want to delete the action %action?', array('%action' => $this->entity->label())); } /** * {@inheritdoc} */ public function getConfirmText() { - return $this->t('Delete'); + return t('Delete'); } /** @@ -42,7 +42,7 @@ public function submit(array $form, array &$form_state) { $this->entity->delete(); watchdog('user', 'Deleted action %aid (%action)', array('%aid' => $this->entity->id(), '%action' => $this->entity->label())); - drupal_set_message($this->t('Action %action was deleted', array('%action' => $this->entity->label()))); + drupal_set_message(t('Action %action was deleted', array('%action' => $this->entity->label()))); $form_state['redirect'] = 'admin/config/system/actions'; } diff --git a/core/modules/book/book.services.yml b/core/modules/book/book.services.yml index 9d8c140..283efd8 100644 --- a/core/modules/book/book.services.yml +++ b/core/modules/book/book.services.yml @@ -1,4 +1,9 @@ services: + book.breadcrumb: + class: Drupal\book\BookBreadcrumbBuilder + arguments: ['@plugin.manager.entity', '@access_manager', '@string_translation'] + tags: + - { name: breadcrumb_builder, priority: 701 } book.manager: class: Drupal\book\BookManager arguments: ['@database', '@plugin.manager.entity'] diff --git a/core/modules/book/lib/Drupal/book/BookBreadcrumbBuilder.php b/core/modules/book/lib/Drupal/book/BookBreadcrumbBuilder.php new file mode 100644 index 0000000..80838bc --- /dev/null +++ b/core/modules/book/lib/Drupal/book/BookBreadcrumbBuilder.php @@ -0,0 +1,107 @@ +menuLinkStorage = $entity_manager->getStorageController('menu_link'); + $this->accessManager = $access_manager; + $this->translation = $translation; + } + + /** + * {@inheritdoc} + */ + public function build(array $attributes) { + // @todo - like \Drupal\forum\ForumBreadcrumbBuilder this depends on the + // legacy non-route node view. It must be updated once that's converted. + if (!empty($attributes['_drupal_menu_item']) && !empty($attributes['_drupal_menu_item']['map'][1]->book)) { + $mlids = array(); + // @todo Replace with link generator service when + // https://drupal.org/node/2047619 lands. + $links = array(l($this->translation->translate('Home'), '')); + $book = $attributes['_drupal_menu_item']['map'][1]->book; + $depth = 1; + // We skip the current node. + while (!empty($book['p' . ($depth + 1)])) { + $mlids[] = $book['p' . $depth]; + $depth++; + } + $menu_links = $this->menuLinkStorage->loadMultiple($mlids); + if (count($menu_links) > 0) { + $depth = 1; + while (!empty($book['p' . ($depth + 1)])) { + if (!empty($menu_links[$book['p' . $depth]]) && ($menu_link = $menu_links[$book['p' . $depth]])) { + // Legacy hook_menu page callback. + // @todo change this once thie node view route is converted. + if ($item = menu_get_item($menu_link->link_path)) { + if ($item['access']) { + $links[] = l($menu_link->label(), $menu_link->link_path, $menu_link->options); + } + } + } + $depth++; + } + } + return $links; + } + } + +} diff --git a/core/modules/filter/lib/Drupal/filter/Entity/FilterFormat.php b/core/modules/filter/lib/Drupal/filter/Entity/FilterFormat.php index 7bc107d..cc7a3c7 100644 --- a/core/modules/filter/lib/Drupal/filter/Entity/FilterFormat.php +++ b/core/modules/filter/lib/Drupal/filter/Entity/FilterFormat.php @@ -36,7 +36,6 @@ * "id" = "format", * "label" = "name", * "uuid" = "uuid", - * "weight" = "weight", * "status" = "status" * } * ) diff --git a/core/modules/filter/lib/Drupal/filter/FilterFormatListController.php b/core/modules/filter/lib/Drupal/filter/FilterFormatListController.php index 098aa7d..af08b9e 100644 --- a/core/modules/filter/lib/Drupal/filter/FilterFormatListController.php +++ b/core/modules/filter/lib/Drupal/filter/FilterFormatListController.php @@ -9,22 +9,17 @@ use Drupal\Component\Utility\String; use Drupal\Core\Config\ConfigFactory; -use Drupal\Core\Config\Entity\DraggableListController; -use Drupal\Core\Entity\EntityControllerInterface; +use Drupal\Core\Config\Entity\ConfigEntityListController; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityStorageControllerInterface; use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\Core\Form\FormInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Defines the filter format list controller. */ -class FilterFormatListController extends DraggableListController implements EntityControllerInterface { - - /** - * {@inheritdoc} - */ - protected $entitiesKey = 'formats'; +class FilterFormatListController extends ConfigEntityListController implements FormInterface { /** * The config factory service. @@ -76,6 +71,13 @@ public function getFormID() { /** * {@inheritdoc} */ + public function render() { + return drupal_get_form($this); + } + + /** + * {@inheritdoc} + */ public function load() { // Only list enabled filters. return array_filter(parent::load(), function ($entity) { @@ -87,8 +89,9 @@ public function load() { * {@inheritdoc} */ public function buildHeader() { - $header['label'] = t('Name'); + $header['name'] = t('Name'); $header['roles'] = t('Roles'); + $header['weight'] = t('Weight'); return $header + parent::buildHeader(); } @@ -96,10 +99,14 @@ public function buildHeader() { * {@inheritdoc} */ public function buildRow(EntityInterface $entity) { + $row['#attributes']['class'][] = 'draggable'; + $row['#weight'] = $entity->get('weight'); + // Check whether this is the fallback text format. This format is available // to all roles and cannot be disabled via the admin interface. - if ($entity->isFallbackFormat()) { - $row['label'] = String::placeholder($entity->label()); + $row['#is_fallback'] = $entity->isFallbackFormat(); + if ($row['#is_fallback']) { + $row['name'] = array('#markup' => String::placeholder($entity->label())); $fallback_choice = $this->configFactory->get('filter.settings')->get('always_show_fallback_choice'); if ($fallback_choice) { @@ -110,12 +117,20 @@ public function buildRow(EntityInterface $entity) { } } else { - $row['label'] = $this->getLabel($entity); + $row['name'] = array('#markup' => $this->getLabel($entity)); $roles = array_map('\Drupal\Component\Utility\String::checkPlain', filter_get_roles_by_format($entity)); $roles_markup = $roles ? implode(', ', $roles) : t('No roles may use this format'); } - $row['roles'] = !empty($this->weightKey) ? array('#markup' => $roles_markup) : $roles_markup; + $row['roles'] = array('#markup' => $roles_markup); + + $row['weight'] = array( + '#type' => 'weight', + '#title' => t('Weight for @title', array('@title' => $entity->label())), + '#title_display' => 'invisible', + '#default_value' => $entity->get('weight'), + '#attributes' => array('class' => array('text-format-order-weight')), + ); return $row + parent::buildRow($entity); } @@ -144,15 +159,47 @@ public function getOperations(EntityInterface $entity) { * {@inheritdoc} */ public function buildForm(array $form, array &$form_state) { - $form = parent::buildForm($form, $form_state); - $form['actions']['submit']['#value'] = t('Save changes'); + $form['#tree'] = TRUE; + $form['formats'] = array( + '#type' => 'table', + '#header' => $this->buildHeader(), + '#empty' => t('There is no @label yet.', array('@label' => $this->entityInfo['label'])), + '#tabledrag' => array( + array('order', 'sibling', 'text-format-order-weight'), + ), + ); + foreach ($this->load() as $entity) { + $form['formats'][$entity->id()] = $this->buildRow($entity); + } + $form['actions']['#type'] = 'actions'; + $form['actions']['submit'] = array( + '#type' => 'submit', + '#value' => t('Save changes'), + '#button_type' => 'primary', + ); return $form; } + + /** + * {@inheritdoc} + */ + public function validateForm(array &$form, array &$form_state) { + } + /** * {@inheritdoc} */ public function submitForm(array &$form, array &$form_state) { - parent::submitForm($form, $form_state); + $values = $form_state['values']['formats']; + + $entities = $this->storage->loadMultiple(array_keys($values)); + foreach ($values as $id => $value) { + if (isset($entities[$id]) && $value['weight'] != $entities[$id]->get('weight')) { + // Update changed weight. + $entities[$id]->set('weight', $value['weight']); + $entities[$id]->save(); + } + } filter_formats_reset(); drupal_set_message(t('The text format ordering has been saved.')); diff --git a/core/modules/language/language.admin.inc b/core/modules/language/language.admin.inc index 47eea47..979419e 100644 --- a/core/modules/language/language.admin.inc +++ b/core/modules/language/language.admin.inc @@ -214,6 +214,47 @@ function language_admin_edit_form_submit($form, &$form_state) { } /** + * User interface for the language deletion confirmation screen. + */ +function language_admin_delete_form($form, &$form_state, $language) { + $langcode = $language->id; + + if (language_default()->id == $langcode) { + drupal_set_message(t('The default language cannot be deleted.')); + return new RedirectResponse(url('admin/config/regional/language', array('absolute' => TRUE))); + } + + // For other languages, warn the user that data loss is ahead. + $languages = language_list(); + + if (!isset($languages[$langcode])) { + throw new NotFoundHttpException(); + } + else { + $form['langcode'] = array('#type' => 'value', '#value' => $langcode); + return confirm_form($form, t('Are you sure you want to delete the language %language?', array('%language' => $languages[$langcode]->name)), 'admin/config/regional/language', t('Deleting a language will remove all interface translations associated with it, and posts in this language will be set to be language neutral. This action cannot be undone.'), t('Delete'), t('Cancel')); + } +} + +/** + * Process language deletion submissions. + */ +function language_admin_delete_form_submit($form, &$form_state) { + $langcode = $form_state['values']['langcode']; + $languages = language_list(); + $language = $languages[$langcode]; + + $success = language_delete($langcode); + + if ($success) { + $t_args = array('%language' => $language->name, '%langcode' => $language->id); + drupal_set_message(t('The %language (%langcode) language has been removed.', $t_args)); + } + + $form_state['redirect'] = 'admin/config/regional/language'; +} + +/** * Prepare a language code list for unused predefined languages. */ function language_admin_predefined_list() { @@ -671,6 +712,31 @@ function language_negotiation_configure_browser_form_submit($form, &$form_state) } /** + * Form for deleting a browser language negotiation mapping. + */ +function language_negotiation_configure_browser_delete_form($form, &$form_state, $browser_langcode) { + $form_state['browser_langcode'] = $browser_langcode; + $question = t('Are you sure you want to delete %browser_langcode?', array( + '%browser_langcode' => $browser_langcode, + )); + $path = 'admin/config/regional/language/detection/browser'; + return confirm_form($form, $question, $path, ''); +} + +/** + * Form submit handler to delete a browser language negotiation mapping. + */ +function language_negotiation_configure_browser_delete_form_submit($form, &$form_state) { + $browser_langcode = $form_state['browser_langcode']; + $mappings = language_get_browser_drupal_langcode_mappings(); + if (array_key_exists($browser_langcode, $mappings)) { + unset($mappings[$browser_langcode]); + language_set_browser_drupal_langcode_mappings($mappings); + } + $form_state['redirect'] = 'admin/config/regional/language/detection/browser'; +} + +/** * Returns the content language settings form. */ function language_content_settings_page() { diff --git a/core/modules/language/language.module b/core/modules/language/language.module index f092c86..4d2688c 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -94,7 +94,12 @@ function language_menu() { 'file' => 'language.admin.inc', ); $items['admin/config/regional/language/delete/%language'] = array( - 'route_name' => 'language_delete', + 'title' => 'Confirm delete', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('language_admin_delete_form', 5), + 'access callback' => 'language_access_language_edit_or_delete', + 'access arguments' => array(5), + 'file' => 'language.admin.inc', ); // Language negotiation. @@ -125,6 +130,13 @@ function language_menu() { 'file' => 'language.admin.inc', 'type' => MENU_VISIBLE_IN_BREADCRUMB, ); + $items['admin/config/regional/language/detection/browser/delete/%'] = array( + 'title' => 'Delete language mapping', + 'page arguments' => array('language_negotiation_configure_browser_delete_form', 7), + 'type' => MENU_CALLBACK, + 'access arguments' => array('administer languages'), + 'file' => 'language.admin.inc', + ); $items['admin/config/regional/language/detection/selected'] = array( 'title' => 'Selected language detection configuration', 'route_name' => 'language_negotiation_selected', diff --git a/core/modules/language/language.routing.yml b/core/modules/language/language.routing.yml index 5158655..e75e1ce 100644 --- a/core/modules/language/language.routing.yml +++ b/core/modules/language/language.routing.yml @@ -25,17 +25,3 @@ language_admin_overview: _entity_list: 'language_entity' requirements: _permission: 'administer languages' - -language_delete: - pattern: '/admin/config/regional/language/delete/{language_entity}' - defaults: - _entity_form: 'language_entity.delete' - requirements: - _entity_access: 'language_entity.delete' - -language_negotiation_browser_delete: - pattern: 'admin/config/regional/language/detection/browser/delete/{browser_langcode}' - defaults: - _form: '\Drupal\language\Form\NegotiationBrowserDeleteForm' - requirements: - _permission: 'administer languages' diff --git a/core/modules/language/lib/Drupal/language/Entity/Language.php b/core/modules/language/lib/Drupal/language/Entity/Language.php index 23f65db..15c6a67 100644 --- a/core/modules/language/lib/Drupal/language/Entity/Language.php +++ b/core/modules/language/lib/Drupal/language/Entity/Language.php @@ -24,16 +24,12 @@ * controllers = { * "storage" = "Drupal\Core\Config\Entity\ConfigStorageController", * "list" = "Drupal\language\LanguageListController", - * "access" = "Drupal\language\LanguageAccessController", - * "form" = { - * "delete" = "Drupal\language\Form\LanguageDeleteForm" - * } + * "access" = "Drupal\language\LanguageAccessController" * }, * config_prefix = "language.entity", * entity_keys = { * "id" = "id", * "label" = "label", - * "weight" = "weight", * "uuid" = "uuid" * } * ) diff --git a/core/modules/language/lib/Drupal/language/Form/LanguageDeleteForm.php b/core/modules/language/lib/Drupal/language/Form/LanguageDeleteForm.php deleted file mode 100644 index e4f0eb1..0000000 --- a/core/modules/language/lib/Drupal/language/Form/LanguageDeleteForm.php +++ /dev/null @@ -1,119 +0,0 @@ -urlGenerator = $url_generator; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('url_generator') - ); - } - - /** - * {@inheritdoc} - */ - public function getQuestion() { - return $this->t('Are you sure you want to delete the language %language?', array('%language' => $this->entity->label())); - } - - /** - * {@inheritdoc} - */ - public function getCancelPath() { - return 'admin/config/regional/language'; - } - - /** - * {@inheritdoc} - */ - public function getDescription() { - return $this->t('Deleting a language will remove all interface translations associated with it, and content in this language will be set to be language neutral. This action cannot be undone.'); - } - - /** - * {@inheritdoc} - */ - public function getConfirmText() { - return $this->t('Delete'); - } - - /** - * {@inheritdoc} - */ - public function getFormID() { - return 'language_delete_form'; - } - - /** - * {@inheritdoc} - */ - public function buildForm(array $form, array &$form_state) { - $langcode = $this->entity->id(); - - // Warn and redirect user when attempting to delete the default language. - if (language_default()->id == $langcode) { - drupal_set_message($this->t('The default language cannot be deleted.')); - $url = $this->urlGenerator->generateFromPath('admin/config/regional/language', array('absolute' => TRUE)); - return new RedirectResponse($url); - } - - // Throw a 404 when attempting to delete a non-existing language. - $languages = language_list(); - if (!isset($languages[$langcode])) { - throw new NotFoundHttpException(); - } - return parent::buildForm($form, $form_state); - } - - /** - * {@inheritdoc} - */ - public function submit(array $form, array &$form_state) { - // @todo This should be replaced with $this->entity->delete() when the - // additional logic in language_delete() is ported. - $success = language_delete($this->entity->id()); - - if ($success) { - drupal_set_message($this->t('The %language (%langcode) language has been removed.', array('%language' => $this->entity->label(), '%langcode' => $this->entity->id()))); - } - - $form_state['redirect'] = 'admin/config/regional/language'; - } - -} diff --git a/core/modules/language/lib/Drupal/language/Form/NegotiationBrowserDeleteForm.php b/core/modules/language/lib/Drupal/language/Form/NegotiationBrowserDeleteForm.php deleted file mode 100644 index cb8db31..0000000 --- a/core/modules/language/lib/Drupal/language/Form/NegotiationBrowserDeleteForm.php +++ /dev/null @@ -1,69 +0,0 @@ -t('Are you sure you want to delete %browser_langcode?', array('%browser_langcode' => $this->browserLangcode)); - } - - /** - * {@inheritdoc} - */ - public function getCancelPath() { - return 'admin/config/regional/language/detection/browser'; - } - - /** - * {@inheritdoc} - */ - public function getFormID() { - return 'language_negotiation_configure_browser_delete_form'; - } - - /** - * {@inheritdoc} - */ - public function buildForm(array $form, array &$form_state, $browser_langcode = NULL) { - $this->browserLangcode = $browser_langcode; - - return parent::buildForm($form, $form_state); - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, array &$form_state) { - $mappings = language_get_browser_drupal_langcode_mappings(); - - if (array_key_exists($this->browserLangcode, $mappings)) { - unset($mappings[$this->browserLangcode]); - language_set_browser_drupal_langcode_mappings($mappings); - } - - $form_state['redirect'] = 'admin/config/regional/language/detection/browser'; - } - -} diff --git a/core/modules/language/lib/Drupal/language/LanguageListController.php b/core/modules/language/lib/Drupal/language/LanguageListController.php index d33b9f4..8abeb8b 100644 --- a/core/modules/language/lib/Drupal/language/LanguageListController.php +++ b/core/modules/language/lib/Drupal/language/LanguageListController.php @@ -6,18 +6,14 @@ namespace Drupal\language; -use Drupal\Core\Config\Entity\DraggableListController; +use Drupal\Core\Config\Entity\ConfigEntityListController; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Form\FormInterface; /** * User interface for the language overview screen. */ -class LanguageListController extends DraggableListController { - - /** - * {@inheritdoc} - */ - protected $entitiesKey = 'languages'; +class LanguageListController extends ConfigEntityListController implements FormInterface { /** * {@inheritdoc} @@ -65,6 +61,7 @@ public function getOperations(EntityInterface $entity) { */ public function buildHeader() { $header['label'] = t('Name'); + $header['weight'] = t('Weight'); return $header + parent::buildHeader(); } @@ -72,7 +69,23 @@ public function buildHeader() { * {@inheritdoc} */ public function buildRow(EntityInterface $entity) { - $row['label'] = $this->getLabel($entity); + $row['#attributes']['class'][] = 'draggable'; + + $row['label'] = array( + '#markup' => check_plain($entity->get('label')), + ); + + $row['#weight'] = $entity->get('weight'); + // Add weight column. + $row['weight'] = array( + '#type' => 'weight', + '#title' => t('Weight for @title', array('@title' => $entity->label())), + '#title_display' => 'invisible', + '#default_value' => $entity->get('weight'), + '#attributes' => array('class' => array('weight')), + '#delta' => 30, + ); + return $row + parent::buildRow($entity); } @@ -80,17 +93,52 @@ public function buildRow(EntityInterface $entity) { * {@inheritdoc} */ public function buildForm(array $form, array &$form_state) { - $form = parent::buildForm($form, $form_state); - $form[$this->entitiesKey]['#languages'] = $this->entities; - $form['actions']['submit']['#value'] = t('Save configuration'); + $languages = $this->load(); + + $form['languages'] = array( + '#languages' => $languages, + '#type' => 'table', + '#header' => $this->buildHeader(), + '#empty' => t('There are no languages', array('@label' => $this->entityInfo['label'])), + '#tabledrag' => array( + array('order', 'sibling', 'weight'), + ), + ); + + foreach ($languages as $entity) { + $form['languages'][$entity->id()] = $this->buildRow($entity); + } + + $form['actions']['#type'] = 'actions'; + $form['actions']['submit'] = array( + '#type' => 'submit', + '#value' => t('Save configuration'), + ); + return $form; } /** * {@inheritdoc} */ + public function validateForm(array &$form, array &$form_state) { + // No validation. + } + + /** + * {@inheritdoc} + */ public function submitForm(array &$form, array &$form_state) { - parent::submitForm($form, $form_state); + $languages = $form_state['values']['languages']; + + $language_entities = $this->load(); + foreach ($languages as $langcode => $language) { + if (isset($language_entities[$langcode]) && $language['weight'] != $language_entities[$langcode]->get('weight')) { + // Update changed weight. + $language_entities[$langcode]->set('weight', $language['weight']); + $language_entities[$langcode]->save(); + } + } // Kill the static cache in language_list(). drupal_static_reset('language_list'); @@ -101,4 +149,10 @@ public function submitForm(array &$form, array &$form_state) { drupal_set_message(t('Configuration saved.')); } + /** + * {@inheritdoc} + */ + public function render() { + return drupal_get_form($this); + } } diff --git a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkBreadcrumbBuilder.php b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkBreadcrumbBuilder.php deleted file mode 100644 index acece08..0000000 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkBreadcrumbBuilder.php +++ /dev/null @@ -1,26 +0,0 @@ -isNew()) { - // Get the human-readable menu title from the given menu name. - $titles = menu_get_menus(); - $current_title = $titles[$menu_link->menu_name]; - - // Get the current breadcrumb and add a link to that menu's overview page. - $breadcrumb = menu_get_active_breadcrumb(); - $breadcrumb[] = l($current_title, 'admin/structure/menu/manage/' . $menu_link->menu_name); - drupal_set_breadcrumb($breadcrumb); - } - $form['link_title'] = array( '#type' => 'textfield', '#title' => t('Menu link title'), diff --git a/core/modules/menu_link/menu_link.services.yml b/core/modules/menu_link/menu_link.services.yml deleted file mode 100644 index a428476..0000000 --- a/core/modules/menu_link/menu_link.services.yml +++ /dev/null @@ -1,5 +0,0 @@ -services: - menu_link.breadcrumb: - class: Drupal\menu_link\MenuLinkBreadcrumbBuilder - tags: - - { name: breadcrumb_builder, priority: 0 } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageTest.php index 353a687..6facbdb 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageTest.php @@ -118,6 +118,7 @@ function testNodeAccessPrivate() { $node = $this->drupalCreateNode(array('body' => array(array()), 'langcode' => 'hu')); $this->assertTrue($node->language()->id == 'hu', 'Node created as Hungarian.'); + $expected_node_access = array('view' => TRUE, 'update' => FALSE, 'delete' => FALSE); $expected_node_access_no_access = array('view' => FALSE, 'update' => FALSE, 'delete' => FALSE); // Creating a private node with langcode Hungarian, will be saved as the diff --git a/core/modules/system/lib/Drupal/system/PathBasedBreadcrumbBuilder.php b/core/modules/system/lib/Drupal/system/PathBasedBreadcrumbBuilder.php new file mode 100644 index 0000000..debe9ca --- /dev/null +++ b/core/modules/system/lib/Drupal/system/PathBasedBreadcrumbBuilder.php @@ -0,0 +1,174 @@ +request = $request; + $this->accessManager = $access_manager; + $this->translation = $translation; + $this->menuStorage = $entity_manager->getStorageController('menu'); + $this->router = $router; + $this->pathProcessor = $path_processor; + } + + /** + * {@inheritdoc} + */ + public function build(array $attributes) { + $links = array(); + + // Custom breadcrumb behaviour for editing menu links, we append a link to + // the menu in which the link is found. + if (!empty($attributes['_route']) && $attributes['_route'] == 'menu_link_edit' && !empty($attributes['menu_link'])) { + $menu_link = $attributes['menu_link']; + if (!$menu_link->isNew()) { + // Add a link to the menu admin screen. + $menu = $this->menuStorage->load($menu_link->menu_name); + $links[] = l($menu->label(), 'admin/structure/menu/manage/' . $menu_link->menu_name); + } + } + + // General path-based breadcrumbs. Use the original, aliased path. + $path_elements = explode('/', trim($this->request->getPathInfo(), '/')); + while (count($path_elements) > 1) { + array_pop($path_elements); + // Copy the path elements for up-casting. + $pattern = implode('/', $path_elements); + $route_request = $this->getRequestForPath($pattern); + if ($route_request) { + $access = FALSE; + // @todo - remove this once all of core is converted to the new router. + if ($route_request->attributes->get('_legacy')) { + $menu_item = $route_request->attributes->get('_drupal_menu_item'); + $access = $menu_item['access']; + $title = $menu_item['title']; + } + else { + $route_name = $route_request->attributes->get(RouteObjectInterface::ROUTE_NAME); + // Note that the parameters don't really matter here since we're + // passing in the request which already has the upcast attributes. + $parameters = array(); + $access = $this->accessManager->checkNamedRoute($route_name, $parameters, $route_request); + $title = $route_request->attributes->get('_title'); + } + if ($access) { + if (!$title) { + $title = end($path_elements); + } + // @todo Replace with a #type => link render element when + // https://drupal.org/node/2047619 lands. + $links[] = l($title, $route_request->attributes->get('_system_path')); + } + } + + } + // @todo Replace with a #type => link render element when + // https://drupal.org/node/2047619 lands. + $links[] = l($this->translation->translate('Home'), ''); + return array_reverse($links); + } + + /** + * Matches a path in the router. + * + * @param string $path + * The request path. + + * @return \Symfony\Component\HttpFoundation\Request + * A populated request object or NULL if the patch couldn't be matched. + */ + protected function getRequestForPath($path) { + $request = Request::create($path); + $processed = $this->pathProcessor->processInbound($path, $request); + $request->attributes->set('_system_path', $processed); + // Attempt to match this path to provide a fully built request. + try { + $request->attributes->add($this->router->matchRequest($request)); + return $request; + } + catch (NotFoundHttpException $e) { + return NULL; + } + catch (ResourceNotFoundException $e) { + return NULL; + } + } + +} diff --git a/core/modules/system/lib/Drupal/system/Tests/Menu/TrailTest.php b/core/modules/system/lib/Drupal/system/Tests/Menu/TrailTest.php index fbd3e34..4da001e 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Menu/TrailTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Menu/TrailTest.php @@ -83,23 +83,9 @@ function testMenuTreeSetPath() { 'admin/config/development/menu-trail' => t('Menu trail - Case 2'), ); - $override_breadcrumb = $config + array( - 'admin/config/system' => t('System'), - 'admin/config/system/site-information' => t('Site information'), - ); - $override_tree = $config_tree + array( - 'admin/config/system' => t('System'), - 'admin/config/system/site-information' => t('Site information'), - ); - // Test the tree generation for the Administration menu. \Drupal::state()->delete('menu_test.menu_tree_set_path'); $this->assertBreadcrumb('admin/config/development/menu-trail', $breadcrumb, t('Menu trail - Case 2'), $tree); - - // Override the active trail for the Administration tree; it should affect - // the breadcrumbs and Administration tree. - \Drupal::state()->set('menu_test.menu_tree_set_path', $test_menu_path); - $this->assertBreadcrumb('admin/config/development/menu-trail', $override_breadcrumb, t('Menu trail - Case 2'), $override_tree); } /** diff --git a/core/modules/system/lib/Drupal/system/Tests/Menu/TreeAccessTest.php b/core/modules/system/lib/Drupal/system/Tests/Menu/TreeAccessTest.php index 263e2fc..df10877 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Menu/TreeAccessTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Menu/TreeAccessTest.php @@ -33,6 +33,13 @@ class TreeAccessTest extends DrupalUnitTestBase { */ protected $routeCollection; + /** + * Modules to enable. + * + * @var array + */ + public static $modules = array('menu_link'); + public static function getInfo() { return array( 'name' => 'Menu tree access', diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index 6339d1c..4d7aae0 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -940,53 +940,6 @@ function hook_local_task_alter(&$local_tasks) { } /** - * Alter links in the active trail before it is rendered as the breadcrumb. - * - * This hook is invoked by menu_get_active_breadcrumb() and allows alteration - * of the breadcrumb links for the current page, which may be preferred instead - * of setting a custom breadcrumb via drupal_set_breadcrumb(). - * - * Implementations should take into account that menu_get_active_breadcrumb() - * subsequently performs the following adjustments to the active trail *after* - * this hook has been invoked: - * - The last link in $active_trail is removed, if its 'href' is identical to - * the 'href' of $item. This happens, because the breadcrumb normally does - * not contain a link to the current page. - * - The (second to) last link in $active_trail is removed, if the current $item - * is a MENU_DEFAULT_LOCAL_TASK. This happens in order to do not show a link - * to the current page, when being on the path for the default local task; - * e.g. when being on the path node/%/view, the breadcrumb should not contain - * a link to node/%. - * - * Each link in the active trail must contain: - * - title: The localized title of the link. - * - href: The system path to link to. - * - localized_options: An array of options to pass to url(). - * - * @param $active_trail - * An array containing breadcrumb links for the current page. - * @param $item - * The menu router item of the current page. - * - * @see drupal_set_breadcrumb() - * @see menu_get_active_breadcrumb() - * @see menu_get_active_trail() - * @see menu_set_active_trail() - */ -function hook_menu_breadcrumb_alter(&$active_trail, $item) { - // Always display a link to the current page by duplicating the last link in - // the active trail. This means that menu_get_active_breadcrumb() will remove - // the last link (for the current page), but since it is added once more here, - // it will appear. - if (!drupal_is_front_page()) { - $end = end($active_trail); - if ($item['href'] == $end['href']) { - $active_trail[] = $end; - } - } -} - -/** * Alter contextual links before they are rendered. * * This hook is invoked by menu_contextual_links(). The system-determined diff --git a/core/modules/system/system.services.yml b/core/modules/system/system.services.yml index 08d67ad..36fe8eb 100644 --- a/core/modules/system/system.services.yml +++ b/core/modules/system/system.services.yml @@ -10,6 +10,11 @@ services: class: Drupal\system\LegacyBreadcrumbBuilder tags: - {name: breadcrumb_builder, priority: 500} + system.breadcrumb.default: + class: Drupal\system\PathBasedBreadcrumbBuilder + arguments: ['@request', '@plugin.manager.entity', '@access_manager', '@string_translation', '@router', '@path_processor_manager'] + tags: + - { name: breadcrumb_builder, priority: 0 } path_processor.files: class: Drupal\system\PathProcessor\PathProcessorFiles tags: diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Vocabulary.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Vocabulary.php index 8c20176..0057036 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Vocabulary.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Vocabulary.php @@ -35,7 +35,6 @@ * entity_keys = { * "id" = "vid", * "label" = "name", - * "weight" = "weight", * "uuid" = "uuid" * } * ) diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyListController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyListController.php index 3ce091b..a5480c5 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyListController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyListController.php @@ -7,18 +7,14 @@ namespace Drupal\taxonomy; -use Drupal\Core\Config\Entity\DraggableListController; +use Drupal\Core\Config\Entity\ConfigEntityListController; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Form\FormInterface; /** * Provides a listing of vocabularies. */ -class VocabularyListController extends DraggableListController { - - /** - * {@inheritdoc} - */ - protected $entitiesKey = 'vocabularies'; +class VocabularyListController extends ConfigEntityListController implements FormInterface { /** * {@inheritdoc} @@ -69,7 +65,21 @@ public function buildHeader() { * {@inheritdoc} */ public function buildRow(EntityInterface $entity) { - $row['label'] = $this->getLabel($entity); + // Override default values to markup elements. + $row['#attributes']['class'][] = 'draggable'; + + $row['label'] = array( + '#markup' => $this->getLabel($entity), + ); + $row['#weight'] = $entity->get('weight'); + // Add weight column. + $row['weight'] = array( + '#type' => 'weight', + '#title' => t('Weight for @title', array('@title' => $entity->label())), + '#title_display' => 'invisible', + '#default_value' => $entity->get('weight'), + '#attributes' => array('class' => array('weight')), + ); return $row + parent::buildRow($entity); } @@ -78,13 +88,22 @@ public function buildRow(EntityInterface $entity) { */ public function render() { $entities = $this->load(); - // If there are not multiple vocabularies, disable dragging by unsetting the - // weight key. - if (count($entities) <= 1) { - unset($this->weightKey); + if (count($entities) > 1) { + // Creates a form for manipulating vocabulary weights if more then one + // vocabulary exists. + return drupal_get_form($this); + } + $build = array( + '#theme' => 'table', + '#header' => $this->buildHeader(), + '#rows' => array(), + '#empty' => t('No vocabularies available. Add vocabulary.', array('@link' => url('admin/structure/taxonomy/add'))), + ); + unset($build['#header']['weight']); + foreach ($entities as $entity) { + $row['label'] = $this->getLabel($entity); + $build['#rows'][$entity->id()] = $row + parent::buildRow($entity); } - $build = parent::render(); - $build['#empty'] = t('No vocabularies available. Add vocabulary.', array('@link' => url('admin/structure/taxonomy/add'))); return $build; } @@ -92,9 +111,27 @@ public function render() { * {@inheritdoc} */ public function buildForm(array $form, array &$form_state) { - $form = parent::buildForm($form, $form_state); - $form['vocabularies']['#attributes'] = array('id' => 'taxonomy'); - $form['actions']['submit']['#value'] = t('Save'); + $form['vocabularies'] = array( + '#type' => 'table', + '#header' => $this->buildHeader(), + '#tabledrag' => array( + array('order', 'sibling', 'weight'), + ), + '#attributes' => array( + 'id' => 'taxonomy', + ), + ); + + foreach ($this->load() as $entity) { + $form['vocabularies'][$entity->id()] = $this->buildRow($entity); + } + + $form['actions']['#type'] = 'actions'; + $form['actions']['submit'] = array( + '#type' => 'submit', + '#value' => t('Save'), + '#button_type' => 'primary', + ); return $form; } @@ -102,8 +139,24 @@ public function buildForm(array $form, array &$form_state) { /** * {@inheritdoc} */ + public function validateForm(array &$form, array &$form_state) { + // No validation. + } + + /** + * {@inheritdoc} + */ public function submitForm(array &$form, array &$form_state) { - parent::submitForm($form, $form_state); + $vocabularies = $form_state['values']['vocabularies']; + + $entities = entity_load_multiple($this->entityType, array_keys($vocabularies)); + foreach ($vocabularies as $id => $value) { + if (isset($entities[$id]) && $value['weight'] != $entities[$id]->get('weight')) { + // Update changed weight. + $entities[$id]->set('weight', $value['weight']); + $entities[$id]->save(); + } + } drupal_set_message(t('The configuration options have been saved.')); } diff --git a/core/modules/user/lib/Drupal/user/AccountFormController.php b/core/modules/user/lib/Drupal/user/AccountFormController.php index 138b86e..e0df82b 100644 --- a/core/modules/user/lib/Drupal/user/AccountFormController.php +++ b/core/modules/user/lib/Drupal/user/AccountFormController.php @@ -36,9 +36,9 @@ public function form(array $form, array &$form_state) { // Only show name field on registration form or user can change own username. $form['account']['name'] = array( '#type' => 'textfield', - '#title' => $this->t('Username'), + '#title' => t('Username'), '#maxlength' => USERNAME_MAX_LENGTH, - '#description' => $this->t('Spaces are allowed; punctuation is not allowed except for periods, hyphens, apostrophes, and underscores.'), + '#description' => t('Spaces are allowed; punctuation is not allowed except for periods, hyphens, apostrophes, and underscores.'), '#required' => TRUE, '#attributes' => array('class' => array('username'), 'autocorrect' => 'off', 'autocomplete' => 'off', 'autocapitalize' => 'off', 'spellcheck' => 'false'), @@ -52,8 +52,8 @@ public function form(array $form, array &$form_state) { // This allows users without e-mail address to be edited and deleted. $form['account']['mail'] = array( '#type' => 'email', - '#title' => $this->t('E-mail address'), - '#description' => $this->t('A valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.'), + '#title' => t('E-mail address'), + '#description' => t('A valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.'), '#required' => !(!$account->getEmail() && user_access('administer users')), '#default_value' => (!$register ? $account->getEmail() : ''), '#attributes' => array('autocomplete' => 'off'), @@ -65,7 +65,7 @@ public function form(array $form, array &$form_state) { $form['account']['pass'] = array( '#type' => 'password_confirm', '#size' => 25, - '#description' => $this->t('To change the current user password, enter the new password in both fields.'), + '#description' => t('To change the current user password, enter the new password in both fields.'), ); // To skip the current password field, the user must have logged in via a @@ -79,9 +79,9 @@ public function form(array $form, array &$form_state) { // password if they logged in via a one-time login link. if (!$pass_reset) { $protected_values['mail'] = $form['account']['mail']['#title']; - $protected_values['pass'] = $this->t('Password'); - $request_new = l($this->t('Request new password'), 'user/password', array('attributes' => array('title' => $this->t('Request new password via e-mail.')))); - $current_pass_description = $this->t('Required if you want to change the %mail or %pass below. !request_new.', array('%mail' => $protected_values['mail'], '%pass' => $protected_values['pass'], '!request_new' => $request_new)); + $protected_values['pass'] = t('Password'); + $request_new = l(t('Request new password'), 'user/password', array('attributes' => array('title' => t('Request new password via e-mail.')))); + $current_pass_description = t('Required if you want to change the %mail or %pass below. !request_new.', array('%mail' => $protected_values['mail'], '%pass' => $protected_values['pass'], '!request_new' => $request_new)); } // The user must enter their current password to change to a new one. @@ -93,7 +93,7 @@ public function form(array $form, array &$form_state) { $form['account']['current_pass'] = array( '#type' => 'password', - '#title' => $this->t('Current password'), + '#title' => t('Current password'), '#size' => 25, '#access' => !empty($protected_values), '#description' => $current_pass_description, @@ -112,7 +112,7 @@ public function form(array $form, array &$form_state) { $form['account']['pass'] = array( '#type' => 'password_confirm', '#size' => 25, - '#description' => $this->t('Provide a password for the new account in both fields.'), + '#description' => t('Provide a password for the new account in both fields.'), '#required' => TRUE, ); } @@ -126,9 +126,9 @@ public function form(array $form, array &$form_state) { $form['account']['status'] = array( '#type' => 'radios', - '#title' => $this->t('Status'), + '#title' => t('Status'), '#default_value' => $status, - '#options' => array($this->t('Blocked'), $this->t('Active')), + '#options' => array(t('Blocked'), t('Active')), '#access' => $admin, ); @@ -148,7 +148,7 @@ public function form(array $form, array &$form_state) { $form['account']['roles'] = array( '#type' => 'checkboxes', - '#title' => $this->t('Roles'), + '#title' => t('Roles'), '#default_value' => (!$register ? $account->getRoles() : array()), '#options' => $roles, '#access' => $roles && user_access('administer permissions'), @@ -157,23 +157,23 @@ public function form(array $form, array &$form_state) { $form['account']['notify'] = array( '#type' => 'checkbox', - '#title' => $this->t('Notify user of new account'), + '#title' => t('Notify user of new account'), '#access' => $register && $admin, ); // Signature. $form['signature_settings'] = array( '#type' => 'details', - '#title' => $this->t('Signature settings'), + '#title' => t('Signature settings'), '#weight' => 1, '#access' => (!$register && $config->get('signatures')), ); $form['signature_settings']['signature'] = array( '#type' => 'text_format', - '#title' => $this->t('Signature'), + '#title' => t('Signature'), '#default_value' => $account->getSignature(), - '#description' => $this->t('Your signature will be publicly displayed at the end of your comments.'), + '#description' => t('Your signature will be publicly displayed at the end of your comments.'), '#format' => $account->getSignatureFormat(), ); @@ -186,7 +186,7 @@ public function form(array $form, array &$form_state) { $interface_language_is_default = language_negotiation_method_get_first(Language::TYPE_INTERFACE) != LANGUAGE_NEGOTIATION_SELECTED; $form['language'] = array( '#type' => language_multilingual() ? 'details' : 'container', - '#title' => $this->t('Language settings'), + '#title' => t('Language settings'), // Display language selector when either creating a user on the admin // interface or editing a user account. '#access' => !$register || user_access('administer users'), @@ -194,15 +194,15 @@ public function form(array $form, array &$form_state) { $form['language']['preferred_langcode'] = array( '#type' => 'language_select', - '#title' => $this->t('Site language'), + '#title' => t('Site language'), '#languages' => Language::STATE_CONFIGURABLE, '#default_value' => $user_preferred_langcode, - '#description' => $interface_language_is_default ? $this->t("This account's preferred language for e-mails and site presentation.") : $this->t("This account's preferred language for e-mails."), + '#description' => $interface_language_is_default ? t("This account's preferred language for e-mails and site presentation.") : t("This account's preferred language for e-mails."), ); $form['language']['preferred_admin_langcode'] = array( '#type' => 'language_select', - '#title' => $this->t('Administration pages language'), + '#title' => t('Administration pages language'), '#languages' => Language::STATE_CONFIGURABLE, '#default_value' => $user_preferred_admin_langcode, '#access' => user_access('access administration pages', $account), @@ -267,7 +267,7 @@ public function validate(array $form, array &$form_state) { ->fetchField(); if ($name_taken) { - form_set_error('name', $this->t('The name %name is already taken.', array('%name' => $form_state['values']['name']))); + form_set_error('name', t('The name %name is already taken.', array('%name' => $form_state['values']['name']))); } } } @@ -286,10 +286,10 @@ public function validate(array $form, array &$form_state) { if ($mail_taken) { // Format error message dependent on whether the user is logged in or not. if ($GLOBALS['user']->isAuthenticated()) { - form_set_error('mail', $this->t('The e-mail address %email is already taken.', array('%email' => $mail))); + form_set_error('mail', t('The e-mail address %email is already taken.', array('%email' => $mail))); } else { - form_set_error('mail', $this->t('The e-mail address %email is already registered. Have you forgotten your password?', array('%email' => $mail, '@password' => url('user/password')))); + form_set_error('mail', t('The e-mail address %email is already registered. Have you forgotten your password?', array('%email' => $mail, '@password' => url('user/password')))); } } } @@ -304,9 +304,8 @@ public function validate(array $form, array &$form_state) { $user_schema = drupal_get_schema('users'); if (drupal_strlen($form_state['values']['signature']) > $user_schema['fields']['signature']['length']) { - form_set_error('signature', $this->t('The signature is too long: it must be %max characters or less.', array('%max' => $user_schema['fields']['signature']['length']))); + form_set_error('signature', t('The signature is too long: it must be %max characters or less.', array('%max' => $user_schema['fields']['signature']['length']))); } } } - } diff --git a/core/modules/user/lib/Drupal/user/AccountSettingsForm.php b/core/modules/user/lib/Drupal/user/AccountSettingsForm.php index c0fcad0..c43dc6d 100644 --- a/core/modules/user/lib/Drupal/user/AccountSettingsForm.php +++ b/core/modules/user/lib/Drupal/user/AccountSettingsForm.php @@ -69,20 +69,20 @@ public function buildForm(array $form, array &$form_state) { // Settings for anonymous users. $form['anonymous_settings'] = array( '#type' => 'details', - '#title' => $this->t('Anonymous users'), + '#title' => t('Anonymous users'), ); $form['anonymous_settings']['anonymous'] = array( '#type' => 'textfield', - '#title' => $this->t('Name'), + '#title' => t('Name'), '#default_value' => $config->get('anonymous'), - '#description' => $this->t('The name used to indicate anonymous users.'), + '#description' => t('The name used to indicate anonymous users.'), '#required' => TRUE, ); // Administrative role option. $form['admin_role'] = array( '#type' => 'details', - '#title' => $this->t('Administrator role'), + '#title' => t('Administrator role'), ); // Do not allow users to set the anonymous or authenticated user roles as the // administrator role. @@ -90,18 +90,18 @@ public function buildForm(array $form, array &$form_state) { unset($roles[DRUPAL_AUTHENTICATED_RID]); $form['admin_role']['user_admin_role'] = array( '#type' => 'select', - '#title' => $this->t('Administrator role'), + '#title' => t('Administrator role'), '#empty_value' => '', '#default_value' => $config->get('admin_role'), '#options' => $roles, - '#description' => $this->t('This role will be automatically assigned new permissions whenever a module is enabled. Changing this setting will not affect existing permissions.'), + '#description' => t('This role will be automatically assigned new permissions whenever a module is enabled. Changing this setting will not affect existing permissions.'), ); // @todo Remove this check once language settings are generalized. if ($this->moduleHandler->moduleExists('content_translation')) { $form['language'] = array( '#type' => 'details', - '#title' => $this->t('Language settings'), + '#title' => t('Language settings'), '#tree' => TRUE, ); $form_state['content_translation']['key'] = 'language'; @@ -111,35 +111,35 @@ public function buildForm(array $form, array &$form_state) { // User registration settings. $form['registration_cancellation'] = array( '#type' => 'details', - '#title' => $this->t('Registration and cancellation'), + '#title' => t('Registration and cancellation'), ); $form['registration_cancellation']['user_register'] = array( '#type' => 'radios', - '#title' => $this->t('Who can register accounts?'), + '#title' => t('Who can register accounts?'), '#default_value' => $config->get('register'), '#options' => array( - USER_REGISTER_ADMINISTRATORS_ONLY => $this->t('Administrators only'), - USER_REGISTER_VISITORS => $this->t('Visitors'), - USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL => $this->t('Visitors, but administrator approval is required'), + USER_REGISTER_ADMINISTRATORS_ONLY => t('Administrators only'), + USER_REGISTER_VISITORS => t('Visitors'), + USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL => t('Visitors, but administrator approval is required'), ) ); $form['registration_cancellation']['user_email_verification'] = array( '#type' => 'checkbox', - '#title' => $this->t('Require e-mail verification when a visitor creates an account.'), + '#title' => t('Require e-mail verification when a visitor creates an account.'), '#default_value' => $config->get('verify_mail'), - '#description' => $this->t('New users will be required to validate their e-mail address prior to logging into the site, and will be assigned a system-generated password. With this setting disabled, users will be logged in immediately upon registering, and may select their own passwords during registration.') + '#description' => t('New users will be required to validate their e-mail address prior to logging into the site, and will be assigned a system-generated password. With this setting disabled, users will be logged in immediately upon registering, and may select their own passwords during registration.') ); $form['registration_cancellation']['user_password_strength'] = array( '#type' => 'checkbox', - '#title' => $this->t('Enable password strength indicator'), + '#title' => t('Enable password strength indicator'), '#default_value' => $config->get('password_strength'), ); form_load_include($form_state, 'inc', 'user', 'user.pages'); $form['registration_cancellation']['user_cancel_method'] = array( '#type' => 'radios', - '#title' => $this->t('When cancelling a user account'), + '#title' => t('When cancelling a user account'), '#default_value' => $config->get('cancel_method'), - '#description' => $this->t('Users with the %select-cancel-method or %administer-users permissions can override this default method.', array('%select-cancel-method' => $this->t('Select method for cancelling account'), '%administer-users' => $this->t('Administer users'), '@permissions-url' => url('admin/people/permissions'))), + '#description' => t('Users with the %select-cancel-method or %administer-users permissions can override this default method.', array('%select-cancel-method' => t('Select method for cancelling account'), '%administer-users' => t('Administer users'), '@permissions-url' => url('admin/people/permissions'))), ); $form['registration_cancellation']['user_cancel_method'] += user_cancel_methods(); foreach (element_children($form['registration_cancellation']['user_cancel_method']) as $key) { @@ -154,142 +154,142 @@ public function buildForm(array $form, array &$form_state) { // Account settings. $form['personalization'] = array( '#type' => 'details', - '#title' => $this->t('Personalization'), + '#title' => t('Personalization'), ); $form['personalization']['user_signatures'] = array( '#type' => 'checkbox', - '#title' => $this->t('Enable signatures.'), + '#title' => t('Enable signatures.'), '#default_value' => $config->get('signatures'), ); // Default notifications address. $form['mail_notification_address'] = array( '#type' => 'email', - '#title' => $this->t('Notification e-mail address'), + '#title' => t('Notification e-mail address'), '#default_value' => $site_config->get('mail_notification'), - '#description' => $this->t("The e-mail address to be used as the 'from' address for all account notifications listed below. If 'Visitors, but administrator approval is required' is selected above, a notification email will also be sent to this address for any new registrations. Leave empty to use the default system e-mail address (%site-email).", array('%site-email' => $site_config->get('mail'))), + '#description' => t("The e-mail address to be used as the 'from' address for all account notifications listed below. If 'Visitors, but administrator approval is required' is selected above, a notification email will also be sent to this address for any new registrations. Leave empty to use the default system e-mail address (%site-email).", array('%site-email' => $site_config->get('mail'))), '#maxlength' => 180, ); $form['email'] = array( '#type' => 'vertical_tabs', - '#title' => $this->t('E-mails'), + '#title' => t('E-mails'), ); // These email tokens are shared for all settings, so just define // the list once to help ensure they stay in sync. - $email_token_help = $this->t('Available variables are: [site:name], [site:url], [user:name], [user:mail], [site:login-url], [site:url-brief], [user:edit-url], [user:one-time-login-url], [user:cancel-url].'); + $email_token_help = t('Available variables are: [site:name], [site:url], [user:name], [user:mail], [site:login-url], [site:url-brief], [user:edit-url], [user:one-time-login-url], [user:cancel-url].'); $form['email_admin_created'] = array( '#type' => 'details', - '#title' => $this->t('Welcome (new user created by administrator)'), + '#title' => t('Welcome (new user created by administrator)'), '#collapsed' => ($config->get('register') != USER_REGISTER_ADMINISTRATORS_ONLY), - '#description' => $this->t('Edit the welcome e-mail messages sent to new member accounts created by an administrator.') . ' ' . $email_token_help, + '#description' => t('Edit the welcome e-mail messages sent to new member accounts created by an administrator.') . ' ' . $email_token_help, '#group' => 'email', ); $form['email_admin_created']['user_mail_register_admin_created_subject'] = array( '#type' => 'textfield', - '#title' => $this->t('Subject'), + '#title' => t('Subject'), '#default_value' => $mail_config->get('register_admin_created.subject'), '#maxlength' => 180, ); $form['email_admin_created']['user_mail_register_admin_created_body'] = array( '#type' => 'textarea', - '#title' => $this->t('Body'), + '#title' => t('Body'), '#default_value' => $mail_config->get('register_admin_created.body'), '#rows' => 15, ); $form['email_pending_approval'] = array( '#type' => 'details', - '#title' => $this->t('Welcome (awaiting approval)'), + '#title' => t('Welcome (awaiting approval)'), '#collapsed' => ($config->get('register') != USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL), - '#description' => $this->t('Edit the welcome e-mail messages sent to new members upon registering, when administrative approval is required.') . ' ' . $email_token_help, + '#description' => t('Edit the welcome e-mail messages sent to new members upon registering, when administrative approval is required.') . ' ' . $email_token_help, '#group' => 'email', ); $form['email_pending_approval']['user_mail_register_pending_approval_subject'] = array( '#type' => 'textfield', - '#title' => $this->t('Subject'), + '#title' => t('Subject'), '#default_value' => $mail_config->get('register_pending_approval.subject'), '#maxlength' => 180, ); $form['email_pending_approval']['user_mail_register_pending_approval_body'] = array( '#type' => 'textarea', - '#title' => $this->t('Body'), + '#title' => t('Body'), '#default_value' => $mail_config->get('register_pending_approval.body'), '#rows' => 8, ); $form['email_pending_approval_admin'] = array( '#type' => 'details', - '#title' => $this->t('Admin (user awaiting approval)'), + '#title' => t('Admin (user awaiting approval)'), '#collapsed' => ($config->get('register') != USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL), - '#description' => $this->t('Edit the e-mail notifying the site administrator that there are new members awaiting administrative approval.') . ' ' . $email_token_help, + '#description' => t('Edit the e-mail notifying the site administrator that there are new members awaiting administrative approval.') . ' ' . $email_token_help, '#group' => 'email', ); $form['email_pending_approval_admin']['register_pending_approval_admin_subject'] = array( '#type' => 'textfield', - '#title' => $this->t('Subject'), + '#title' => t('Subject'), '#default_value' => $mail_config->get('register_pending_approval_admin.subject'), '#maxlength' => 180, ); $form['email_pending_approval_admin']['register_pending_approval_admin_body'] = array( '#type' => 'textarea', - '#title' => $this->t('Body'), + '#title' => t('Body'), '#default_value' => $mail_config->get('register_pending_approval_admin.body'), '#rows' => 8, ); $form['email_no_approval_required'] = array( '#type' => 'details', - '#title' => $this->t('Welcome (no approval required)'), + '#title' => t('Welcome (no approval required)'), '#collapsed' => ($config->get('register') != USER_REGISTER_VISITORS), - '#description' => $this->t('Edit the welcome e-mail messages sent to new members upon registering, when no administrator approval is required.') . ' ' . $email_token_help, + '#description' => t('Edit the welcome e-mail messages sent to new members upon registering, when no administrator approval is required.') . ' ' . $email_token_help, '#group' => 'email', ); $form['email_no_approval_required']['user_mail_register_no_approval_required_subject'] = array( '#type' => 'textfield', - '#title' => $this->t('Subject'), + '#title' => t('Subject'), '#default_value' => $mail_config->get('register_no_approval_required.subject'), '#maxlength' => 180, ); $form['email_no_approval_required']['user_mail_register_no_approval_required_body'] = array( '#type' => 'textarea', - '#title' => $this->t('Body'), + '#title' => t('Body'), '#default_value' => $mail_config->get('register_no_approval_required.body'), '#rows' => 15, ); $form['email_password_reset'] = array( '#type' => 'details', - '#title' => $this->t('Password recovery'), + '#title' => t('Password recovery'), '#collapsed' => TRUE, - '#description' => $this->t('Edit the e-mail messages sent to users who request a new password.') . ' ' . $email_token_help, + '#description' => t('Edit the e-mail messages sent to users who request a new password.') . ' ' . $email_token_help, '#group' => 'email', '#weight' => 10, ); $form['email_password_reset']['user_mail_password_reset_subject'] = array( '#type' => 'textfield', - '#title' => $this->t('Subject'), + '#title' => t('Subject'), '#default_value' => $mail_config->get('password_reset.subject'), '#maxlength' => 180, ); $form['email_password_reset']['user_mail_password_reset_body'] = array( '#type' => 'textarea', - '#title' => $this->t('Body'), + '#title' => t('Body'), '#default_value' => $mail_config->get('password_reset.body'), '#rows' => 12, ); $form['email_activated'] = array( '#type' => 'details', - '#title' => $this->t('Account activation'), + '#title' => t('Account activation'), '#collapsed' => TRUE, - '#description' => $this->t('Enable and edit e-mail messages sent to users upon account activation (when an administrator activates an account of a user who has already registered, on a site where administrative approval is required).') . ' ' . $email_token_help, + '#description' => t('Enable and edit e-mail messages sent to users upon account activation (when an administrator activates an account of a user who has already registered, on a site where administrative approval is required).') . ' ' . $email_token_help, '#group' => 'email', ); $form['email_activated']['user_mail_status_activated_notify'] = array( '#type' => 'checkbox', - '#title' => $this->t('Notify user when account is activated.'), + '#title' => t('Notify user when account is activated.'), '#default_value' => $config->get('notify.status_activated'), ); $form['email_activated']['settings'] = array( @@ -303,27 +303,27 @@ public function buildForm(array $form, array &$form_state) { ); $form['email_activated']['settings']['user_mail_status_activated_subject'] = array( '#type' => 'textfield', - '#title' => $this->t('Subject'), + '#title' => t('Subject'), '#default_value' => $mail_config->get('status_activated.subject'), '#maxlength' => 180, ); $form['email_activated']['settings']['user_mail_status_activated_body'] = array( '#type' => 'textarea', - '#title' => $this->t('Body'), + '#title' => t('Body'), '#default_value' => $mail_config->get('status_activated.body'), '#rows' => 15, ); $form['email_blocked'] = array( '#type' => 'details', - '#title' => $this->t('Account blocked'), + '#title' => t('Account blocked'), '#collapsed' => TRUE, - '#description' => $this->t('Enable and edit e-mail messages sent to users when their accounts are blocked.') . ' ' . $email_token_help, + '#description' => t('Enable and edit e-mail messages sent to users when their accounts are blocked.') . ' ' . $email_token_help, '#group' => 'email', ); $form['email_blocked']['user_mail_status_blocked_notify'] = array( '#type' => 'checkbox', - '#title' => $this->t('Notify user when account is blocked.'), + '#title' => t('Notify user when account is blocked.'), '#default_value' => $config->get('notify.status_blocked'), ); $form['email_blocked']['settings'] = array( @@ -337,47 +337,47 @@ public function buildForm(array $form, array &$form_state) { ); $form['email_blocked']['settings']['user_mail_status_blocked_subject'] = array( '#type' => 'textfield', - '#title' => $this->t('Subject'), + '#title' => t('Subject'), '#default_value' => $mail_config->get('status_blocked.subject'), '#maxlength' => 180, ); $form['email_blocked']['settings']['user_mail_status_blocked_body'] = array( '#type' => 'textarea', - '#title' => $this->t('Body'), + '#title' => t('Body'), '#default_value' => $mail_config->get('status_blocked.body'), '#rows' => 3, ); $form['email_cancel_confirm'] = array( '#type' => 'details', - '#title' => $this->t('Account cancellation confirmation'), + '#title' => t('Account cancellation confirmation'), '#collapsed' => TRUE, - '#description' => $this->t('Edit the e-mail messages sent to users when they attempt to cancel their accounts.') . ' ' . $email_token_help, + '#description' => t('Edit the e-mail messages sent to users when they attempt to cancel their accounts.') . ' ' . $email_token_help, '#group' => 'email', ); $form['email_cancel_confirm']['user_mail_cancel_confirm_subject'] = array( '#type' => 'textfield', - '#title' => $this->t('Subject'), + '#title' => t('Subject'), '#default_value' => $mail_config->get('cancel_confirm.subject'), '#maxlength' => 180, ); $form['email_cancel_confirm']['user_mail_cancel_confirm_body'] = array( '#type' => 'textarea', - '#title' => $this->t('Body'), + '#title' => t('Body'), '#default_value' => $mail_config->get('cancel_confirm.body'), '#rows' => 3, ); $form['email_canceled'] = array( '#type' => 'details', - '#title' => $this->t('Account canceled'), + '#title' => t('Account canceled'), '#collapsed' => TRUE, - '#description' => $this->t('Enable and edit e-mail messages sent to users when their accounts are canceled.') . ' ' . $email_token_help, + '#description' => t('Enable and edit e-mail messages sent to users when their accounts are canceled.') . ' ' . $email_token_help, '#group' => 'email', ); $form['email_canceled']['user_mail_status_canceled_notify'] = array( '#type' => 'checkbox', - '#title' => $this->t('Notify user when account is canceled.'), + '#title' => t('Notify user when account is canceled.'), '#default_value' => $config->get('notify.status_canceled'), ); $form['email_canceled']['settings'] = array( @@ -391,13 +391,13 @@ public function buildForm(array $form, array &$form_state) { ); $form['email_canceled']['settings']['user_mail_status_canceled_subject'] = array( '#type' => 'textfield', - '#title' => $this->t('Subject'), + '#title' => t('Subject'), '#default_value' => $mail_config->get('status_canceled.subject'), '#maxlength' => 180, ); $form['email_canceled']['settings']['user_mail_status_canceled_body'] = array( '#type' => 'textarea', - '#title' => $this->t('Body'), + '#title' => t('Body'), '#default_value' => $mail_config->get('status_canceled.body'), '#rows' => 3, ); diff --git a/core/modules/user/lib/Drupal/user/Entity/Role.php b/core/modules/user/lib/Drupal/user/Entity/Role.php index 8529e87..2703b8b 100644 --- a/core/modules/user/lib/Drupal/user/Entity/Role.php +++ b/core/modules/user/lib/Drupal/user/Entity/Role.php @@ -33,7 +33,6 @@ * entity_keys = { * "id" = "id", * "uuid" = "uuid", - * "weight" = "weight", * "label" = "label" * } * ) diff --git a/core/modules/user/lib/Drupal/user/Form/UserLoginForm.php b/core/modules/user/lib/Drupal/user/Form/UserLoginForm.php index eaf2c39..ebe5b96 100644 --- a/core/modules/user/lib/Drupal/user/Form/UserLoginForm.php +++ b/core/modules/user/lib/Drupal/user/Form/UserLoginForm.php @@ -8,15 +8,18 @@ namespace Drupal\user\Form; use Drupal\Core\Config\ConfigFactory; +use Drupal\Core\Controller\ControllerInterface; +use Drupal\Core\Database\Connection; use Drupal\Core\Flood\FloodInterface; -use Drupal\Core\Form\FormBase; +use Drupal\Core\Form\FormInterface; use Drupal\user\UserStorageControllerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\Request; /** * Provides a user login form. */ -class UserLoginForm extends FormBase { +class UserLoginForm implements FormInterface, ControllerInterface { /** * The config factory. @@ -26,6 +29,13 @@ class UserLoginForm extends FormBase { protected $configFactory; /** + * The request object. + * + * @var \Symfony\Component\HttpFoundation\Request + */ + protected $request; + + /** * The flood service. * * @var \Drupal\Core\Flood\FloodInterface @@ -37,7 +47,7 @@ class UserLoginForm extends FormBase { * * @var \Drupal\user\UserStorageControllerInterface */ - protected $userStorage; + protected $storageController; /** * Constructs a new UserLoginForm. @@ -46,13 +56,13 @@ class UserLoginForm extends FormBase { * The config factory. * @param \Drupal\Core\Flood\FloodInterface $flood * The flood service. - * @param \Drupal\user\UserStorageControllerInterface $user_storage + * @param \Drupal\user\UserStorageControllerInterface $storage_controller * The user storage controller. */ - public function __construct(ConfigFactory $config_factory, FloodInterface $flood, UserStorageControllerInterface $user_storage) { + public function __construct(ConfigFactory $config_factory, FloodInterface $flood, UserStorageControllerInterface $storage_controller) { $this->configFactory = $config_factory; $this->flood = $flood; - $this->userStorage = $user_storage; + $this->storageController = $storage_controller; } /** @@ -76,14 +86,15 @@ public function getFormID() { /** * {@inheritdoc} */ - public function buildForm(array $form, array &$form_state) { + public function buildForm(array $form, array &$form_state, Request $request = NULL) { + $this->request = $request; // Display login form: $form['name'] = array( '#type' => 'textfield', - '#title' => $this->t('Username'), + '#title' => t('Username'), '#size' => 60, '#maxlength' => USERNAME_MAX_LENGTH, - '#description' => $this->t('Enter your @s username.', array('@s' => $this->configFactory->get('system.site')->get('name'))), + '#description' => t('Enter your @s username.', array('@s' => $this->configFactory->get('system.site')->get('name'))), '#required' => TRUE, '#attributes' => array( 'autocorrect' => 'off', @@ -95,14 +106,14 @@ public function buildForm(array $form, array &$form_state) { $form['pass'] = array( '#type' => 'password', - '#title' => $this->t('Password'), + '#title' => t('Password'), '#size' => 60, - '#description' => $this->t('Enter the password that accompanies your username.'), + '#description' => t('Enter the password that accompanies your username.'), '#required' => TRUE, ); $form['actions'] = array('#type' => 'actions'); - $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Log in')); + $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Log in')); $form['#validate'][] = array($this, 'validateName'); $form['#validate'][] = array($this, 'validateAuthentication'); @@ -114,8 +125,14 @@ public function buildForm(array $form, array &$form_state) { /** * {@inheritdoc} */ + public function validateForm(array &$form, array &$form_state) { + } + + /** + * {@inheritdoc} + */ public function submitForm(array &$form, array &$form_state) { - $account = $this->userStorage->load($form_state['uid']); + $account = $this->storageController->load($form_state['uid']); $form_state['redirect'] = 'user/' . $account->id(); user_login_finalize($account); @@ -127,7 +144,7 @@ public function submitForm(array &$form, array &$form_state) { public function validateName(array &$form, array &$form_state) { if (!empty($form_state['values']['name']) && user_is_blocked($form_state['values']['name'])) { // Blocked in user administration. - form_set_error('name', $this->t('The username %name has not been activated or is blocked.', array('%name' => $form_state['values']['name']))); + form_set_error('name', t('The username %name has not been activated or is blocked.', array('%name' => $form_state['values']['name']))); } } @@ -149,7 +166,7 @@ public function validateAuthentication(array &$form, array &$form_state) { $form_state['flood_control_triggered'] = 'ip'; return; } - $accounts = $this->userStorage->loadByProperties(array('name' => $form_state['values']['name'], 'status' => 1)); + $accounts = $this->storageController->loadByProperties(array('name' => $form_state['values']['name'], 'status' => 1)); $account = reset($accounts); if ($account) { if ($flood_config->get('uid_only')) { @@ -161,7 +178,7 @@ public function validateAuthentication(array &$form, array &$form_state) { // The default identifier is a combination of uid and IP address. This // is less secure but more resistant to denial-of-service attacks that // could lock out all users with public user names. - $identifier = $account->id() . '-' . $this->getRequest()->getClientIP(); + $identifier = $account->id() . '-' . $this->request->getClientIP(); } $form_state['flood_control_user_identifier'] = $identifier; @@ -199,19 +216,19 @@ public function validateFinal(array &$form, array &$form_state) { } else { // We did not find a uid, so the limit is IP-based. - form_set_error('name', $this->t('Sorry, too many failed login attempts from your IP address. This IP address is temporarily blocked. Try again later or request a new password.', array('@url' => url('user/password')))); + form_set_error('name', t('Sorry, too many failed login attempts from your IP address. This IP address is temporarily blocked. Try again later or request a new password.', array('@url' => url('user/password')))); } } else { - form_set_error('name', $this->t('Sorry, unrecognized username or password. Have you forgotten your password?', array('@password' => url('user/password', array('query' => array('name' => $form_state['values']['name'])))))); - $accounts = $this->userStorage->loadByProperties(array('name' => $form_state['values']['name'])); + form_set_error('name', t('Sorry, unrecognized username or password. Have you forgotten your password?', array('@password' => url('user/password', array('query' => array('name' => $form_state['values']['name'])))))); + $accounts = $this->storageController->loadByProperties(array('name' => $form_state['values']['name'])); if (!empty($accounts)) { watchdog('user', 'Login attempt failed for %user.', array('%user' => $form_state['values']['name'])); } else { // If the username entered is not a valid user, // only store the IP address. - watchdog('user', 'Login attempt failed from %ip.', array('%ip' => $this->getRequest()->getClientIp())); + watchdog('user', 'Login attempt failed from %ip.', array('%ip' => $this->request->getClientIp())); } } } diff --git a/core/modules/user/lib/Drupal/user/Form/UserPasswordForm.php b/core/modules/user/lib/Drupal/user/Form/UserPasswordForm.php index 1b9bd17..27f40bf 100644 --- a/core/modules/user/lib/Drupal/user/Form/UserPasswordForm.php +++ b/core/modules/user/lib/Drupal/user/Form/UserPasswordForm.php @@ -7,7 +7,8 @@ namespace Drupal\user\Form; -use Drupal\Core\Form\FormBase; +use Drupal\Core\Controller\ControllerInterface; +use Drupal\Core\Form\FormInterface; use Drupal\Core\Language\Language; use Drupal\Core\Language\LanguageManager; use Drupal\user\UserStorageControllerInterface; @@ -17,7 +18,7 @@ /** * Provides a user password reset form. */ -class UserPasswordForm extends FormBase { +class UserPasswordForm implements FormInterface, ControllerInterface { /** * The user storage controller. @@ -69,10 +70,12 @@ public function getFormID() { * @param \Symfony\Component\HttpFoundation\Request $request * The request object. */ - public function buildForm(array $form, array &$form_state) { + public function buildForm(array $form, array &$form_state, Request $request = NULL) { + global $user; + $form['name'] = array( '#type' => 'textfield', - '#title' => $this->t('Username or e-mail address'), + '#title' => t('Username or e-mail address'), '#size' => 60, '#maxlength' => max(USERNAME_MAX_LENGTH, EMAIL_MAX_LENGTH), '#required' => TRUE, @@ -84,21 +87,20 @@ public function buildForm(array $form, array &$form_state) { ), ); // Allow logged in users to request this also. - $user = $this->getCurrentUser(); if ($user->isAuthenticated()) { $form['name']['#type'] = 'value'; $form['name']['#value'] = $user->getEmail(); $form['mail'] = array( '#prefix' => '

', - '#markup' => $this->t('Password reset instructions will be mailed to %email. You must log out to use the password reset link in the e-mail.', array('%email' => $user->getEmail())), + '#markup' => t('Password reset instructions will be mailed to %email. You must log out to use the password reset link in the e-mail.', array('%email' => $user->getEmail())), '#suffix' => '

', ); } else { - $form['name']['#default_value'] = $this->getRequest()->query->get('name'); + $form['name']['#default_value'] = $request->query->get('name'); } $form['actions'] = array('#type' => 'actions'); - $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('E-mail new password')); + $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('E-mail new password')); return $form; } @@ -119,7 +121,7 @@ public function validateForm(array &$form, array &$form_state) { form_set_value(array('#parents' => array('account')), $account, $form_state); } else { - form_set_error('name', $this->t('Sorry, %name is not recognized as a username or an e-mail address.', array('%name' => $name))); + form_set_error('name', t('Sorry, %name is not recognized as a username or an e-mail address.', array('%name' => $name))); } } @@ -134,7 +136,7 @@ public function submitForm(array &$form, array &$form_state) { $mail = _user_mail_notify('password_reset', $account, $langcode); if (!empty($mail)) { watchdog('user', 'Password reset instructions mailed to %name at %email.', array('%name' => $account->getUsername(), '%email' => $account->getEmail())); - drupal_set_message($this->t('Further instructions have been sent to your e-mail address.')); + drupal_set_message(t('Further instructions have been sent to your e-mail address.')); } $form_state['redirect'] = 'user'; diff --git a/core/modules/user/lib/Drupal/user/Form/UserPermissionsForm.php b/core/modules/user/lib/Drupal/user/Form/UserPermissionsForm.php index c76e120..a78eedf 100644 --- a/core/modules/user/lib/Drupal/user/Form/UserPermissionsForm.php +++ b/core/modules/user/lib/Drupal/user/Form/UserPermissionsForm.php @@ -9,15 +9,16 @@ use Drupal\Component\Utility\String; use Drupal\Core\Cache\Cache; +use Drupal\Core\Controller\ControllerInterface; use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\Form\FormBase; +use Drupal\Core\Form\FormInterface; use Drupal\user\RoleStorageControllerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides the user permissions administration form. */ -class UserPermissionsForm extends FormBase { +class UserPermissionsForm implements FormInterface, ControllerInterface { /** * The module handler. @@ -110,7 +111,7 @@ public function buildForm(array $form, array &$form_state) { $form['permissions'] = array( '#type' => 'table', - '#header' => array($this->t('Permission')), + '#header' => array(t('Permission')), '#id' => 'permissions', '#sticky' => TRUE, ); @@ -137,7 +138,7 @@ public function buildForm(array $form, array &$form_state) { $perm_item += array( 'description' => '', 'restrict access' => FALSE, - 'warning' => !empty($perm_item['restrict access']) ? $this->t('Warning: Give to trusted roles only; this permission has security implications.') : '', + 'warning' => !empty($perm_item['restrict access']) ? t('Warning: Give to trusted roles only; this permission has security implications.') : '', ); $options[$perm] = ''; $user_permission_description = array( @@ -172,7 +173,7 @@ public function buildForm(array $form, array &$form_state) { } $form['actions'] = array('#type' => 'actions'); - $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save permissions')); + $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save permissions')); $form['#attached']['library'][] = array('user', 'drupal.user.permissions'); @@ -182,12 +183,18 @@ public function buildForm(array $form, array &$form_state) { /** * {@inheritdoc} */ + public function validateForm(array &$form, array &$form_state) { + } + + /** + * {@inheritdoc} + */ function submitForm(array &$form, array &$form_state) { foreach ($form_state['values']['role_names'] as $role_name => $name) { user_role_change_permissions($role_name, $form_state['values'][$role_name]); } - drupal_set_message($this->t('The changes have been saved.')); + drupal_set_message(t('The changes have been saved.')); // Clear the cached pages and blocks. Cache::invalidateTags(array('content' => TRUE)); diff --git a/core/modules/user/lib/Drupal/user/Form/UserRoleDelete.php b/core/modules/user/lib/Drupal/user/Form/UserRoleDelete.php index fec4793..817de06 100644 --- a/core/modules/user/lib/Drupal/user/Form/UserRoleDelete.php +++ b/core/modules/user/lib/Drupal/user/Form/UserRoleDelete.php @@ -18,7 +18,7 @@ class UserRoleDelete extends EntityConfirmFormBase { * {@inheritdoc} */ public function getQuestion() { - return $this->t('Are you sure you want to delete the role %name?', array('%name' => $this->entity->label())); + return t('Are you sure you want to delete the role %name?', array('%name' => $this->entity->label())); } /** @@ -32,7 +32,7 @@ public function getCancelPath() { * {@inheritdoc} */ public function getConfirmText() { - return $this->t('Delete'); + return t('Delete'); } /** @@ -41,7 +41,7 @@ public function getConfirmText() { public function submit(array $form, array &$form_state) { $this->entity->delete(); watchdog('user', 'Role %name has been deleted.', array('%name' => $this->entity->label())); - drupal_set_message($this->t('Role %name has been deleted.', array('%name' => $this->entity->label()))); + drupal_set_message(t('Role %name has been deleted.', array('%name' => $this->entity->label()))); $form_state['redirect'] = 'admin/people/roles'; } diff --git a/core/modules/user/lib/Drupal/user/ProfileFormController.php b/core/modules/user/lib/Drupal/user/ProfileFormController.php index 88e195d..c10c226 100644 --- a/core/modules/user/lib/Drupal/user/ProfileFormController.php +++ b/core/modules/user/lib/Drupal/user/ProfileFormController.php @@ -20,7 +20,7 @@ protected function actions(array $form, array &$form_state) { $account = $this->entity; $element['delete']['#type'] = 'submit'; - $element['delete']['#value'] = $this->t('Cancel account'); + $element['delete']['#value'] = t('Cancel account'); $element['delete']['#submit'] = array('user_edit_cancel_submit'); $element['delete']['#access'] = $account->id() > 1 && (($account->id() == $GLOBALS['user']->id() && user_access('cancel account')) || user_access('administer users')); @@ -39,7 +39,6 @@ public function save(array $form, array &$form_state) { // information: cache_invalidate_tags(array('content' => TRUE)); - drupal_set_message($this->t('The changes have been saved.')); + drupal_set_message(t('The changes have been saved.')); } - } diff --git a/core/modules/user/lib/Drupal/user/RegisterFormController.php b/core/modules/user/lib/Drupal/user/RegisterFormController.php index 6ace140..4d6b7fc 100644 --- a/core/modules/user/lib/Drupal/user/RegisterFormController.php +++ b/core/modules/user/lib/Drupal/user/RegisterFormController.php @@ -59,7 +59,7 @@ public function form(array $form, array &$form_state) { */ protected function actions(array $form, array &$form_state) { $element = parent::actions($form, $form_state); - $element['submit']['#value'] = $this->t('Create new account'); + $element['submit']['#value'] = t('Create new account'); return $element; } @@ -101,7 +101,7 @@ public function save(array $form, array &$form_state) { $form_state['user'] = $account; $form_state['values']['uid'] = $account->id(); - watchdog('user', 'New user: %name %email.', array('%name' => $form_state['values']['name'], '%email' => '<' . $form_state['values']['mail'] . '>'), WATCHDOG_NOTICE, l($this->t('edit'), 'user/' . $account->id() . '/edit')); + watchdog('user', 'New user: %name %email.', array('%name' => $form_state['values']['name'], '%email' => '<' . $form_state['values']['mail'] . '>'), WATCHDOG_NOTICE, l(t('edit'), 'user/' . $account->id() . '/edit')); // Add plain text password into user account to generate mail tokens. $account->password = $pass; @@ -109,28 +109,28 @@ public function save(array $form, array &$form_state) { // New administrative account without notification. $uri = $account->uri(); if ($admin && !$notify) { - drupal_set_message($this->t('Created a new user account for %name. No e-mail has been sent.', array('@url' => url($uri['path'], $uri['options']), '%name' => $account->getUsername()))); + drupal_set_message(t('Created a new user account for %name. No e-mail has been sent.', array('@url' => url($uri['path'], $uri['options']), '%name' => $account->getUsername()))); } // No e-mail verification required; log in user immediately. elseif (!$admin && !\Drupal::config('user.settings')->get('verify_mail') && $account->isActive()) { _user_mail_notify('register_no_approval_required', $account); user_login_finalize($account); - drupal_set_message($this->t('Registration successful. You are now logged in.')); + drupal_set_message(t('Registration successful. You are now logged in.')); $form_state['redirect'] = ''; } // No administrator approval required. elseif ($account->isActive() || $notify) { if (!$account->getEmail() && $notify) { - drupal_set_message($this->t('The new user %name was created without an email address, so no welcome message was sent.', array('@url' => url($uri['path'], $uri['options']), '%name' => $account->getUsername()))); + drupal_set_message(t('The new user %name was created without an email address, so no welcome message was sent.', array('@url' => url($uri['path'], $uri['options']), '%name' => $account->getUsername()))); } else { $op = $notify ? 'register_admin_created' : 'register_no_approval_required'; if (_user_mail_notify($op, $account)) { if ($notify) { - drupal_set_message($this->t('A welcome message with further instructions has been e-mailed to the new user %name.', array('@url' => url($uri['path'], $uri['options']), '%name' => $account->getUsername()))); + drupal_set_message(t('A welcome message with further instructions has been e-mailed to the new user %name.', array('@url' => url($uri['path'], $uri['options']), '%name' => $account->getUsername()))); } else { - drupal_set_message($this->t('A welcome message with further instructions has been sent to your e-mail address.')); + drupal_set_message(t('A welcome message with further instructions has been sent to your e-mail address.')); $form_state['redirect'] = ''; } } @@ -139,7 +139,7 @@ public function save(array $form, array &$form_state) { // Administrator approval required. else { _user_mail_notify('register_pending_approval', $account); - drupal_set_message($this->t('Thank you for applying for an account. Your account is currently pending approval by the site administrator.
In the meantime, a welcome message with further instructions has been sent to your e-mail address.')); + drupal_set_message(t('Thank you for applying for an account. Your account is currently pending approval by the site administrator.
In the meantime, a welcome message with further instructions has been sent to your e-mail address.')); $form_state['redirect'] = ''; } } diff --git a/core/modules/user/lib/Drupal/user/RoleFormController.php b/core/modules/user/lib/Drupal/user/RoleFormController.php index edb242e..2269844 100644 --- a/core/modules/user/lib/Drupal/user/RoleFormController.php +++ b/core/modules/user/lib/Drupal/user/RoleFormController.php @@ -22,12 +22,12 @@ public function form(array $form, array &$form_state) { $entity = $this->entity; $form['label'] = array( '#type' => 'textfield', - '#title' => $this->t('Role name'), + '#title' => t('Role name'), '#default_value' => $entity->label(), '#size' => 30, '#required' => TRUE, '#maxlength' => 64, - '#description' => $this->t('The name for this role. Example: "Moderator", "Editorial board", "Site architect".'), + '#description' => t('The name for this role. Example: "Moderator", "Editorial board", "Site architect".'), ); $form['id'] = array( '#type' => 'machine_name', @@ -68,12 +68,12 @@ public function save(array $form, array &$form_state) { $entity->set('label', trim($entity->label())); $uri = $entity->uri(); if ($entity->save() == SAVED_UPDATED) { - drupal_set_message($this->t('Role %label has been updated.', array('%label' => $entity->label()))); - watchdog('user', 'Role %label has been updated.', array('%label' => $entity->label()), WATCHDOG_NOTICE, l($this->t('Edit'), $uri['path'])); + drupal_set_message(t('Role %label has been updated.', array('%label' => $entity->label()))); + watchdog('user', 'Role %label has been updated.', array('%label' => $entity->label()), WATCHDOG_NOTICE, l(t('Edit'), $uri['path'])); } else { - drupal_set_message($this->t('Role %label has been added.', array('%label' => $entity->label()))); - watchdog('user', 'Role %label has been added.', array('%label' => $entity->label()), WATCHDOG_NOTICE, l($this->t('Edit'), $uri['path'])); + drupal_set_message(t('Role %label has been added.', array('%label' => $entity->label()))); + watchdog('user', 'Role %label has been added.', array('%label' => $entity->label()), WATCHDOG_NOTICE, l(t('Edit'), $uri['path'])); } $form_state['redirect'] = 'admin/people/roles'; } diff --git a/core/modules/user/lib/Drupal/user/RoleListController.php b/core/modules/user/lib/Drupal/user/RoleListController.php index 3e95aae..ce9594f 100644 --- a/core/modules/user/lib/Drupal/user/RoleListController.php +++ b/core/modules/user/lib/Drupal/user/RoleListController.php @@ -7,13 +7,14 @@ namespace Drupal\user; -use Drupal\Core\Config\Entity\DraggableListController; +use Drupal\Core\Config\Entity\ConfigEntityListController; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Form\FormInterface; /** * Provides a listing of user roles. */ -class RoleListController extends DraggableListController { +class RoleListController extends ConfigEntityListController implements FormInterface { /** * {@inheritdoc} @@ -27,20 +28,13 @@ public function getFormID() { */ public function buildHeader() { $header['label'] = t('Name'); + $header['weight'] = t('Weight'); return $header + parent::buildHeader(); } /** * {@inheritdoc} */ - public function buildRow(EntityInterface $entity) { - $row['label'] = $this->getLabel($entity); - return $row + parent::buildRow($entity); - } - - /** - * {@inheritdoc} - */ public function getOperations(EntityInterface $entity) { $operations = parent::getOperations($entity); @@ -59,10 +53,81 @@ public function getOperations(EntityInterface $entity) { /** * {@inheritdoc} */ + public function buildRow(EntityInterface $entity) { + // Override default values to markup elements. + $row['#attributes']['class'][] = 'draggable'; + + $row['label'] = array( + '#markup' => $this->getLabel($entity), + ); + $row['#weight'] = $entity->get('weight'); + // Add weight column. + $row['weight'] = array( + '#type' => 'weight', + '#title' => t('Weight for @title', array('@title' => $entity->label())), + '#title_display' => 'invisible', + '#default_value' => $entity->get('weight'), + '#attributes' => array('class' => array('weight')), + ); + return $row + parent::buildRow($entity); + } + + /** + * {@inheritdoc} + */ + public function render() { + return drupal_get_form($this); + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, array &$form_state) { + $form['entities'] = array( + '#type' => 'table', + '#header' => $this->buildHeader(), + '#empty' => t('There is no @label yet.', array('@label' => $this->entityInfo['label'])), + '#tabledrag' => array( + array('order', 'sibling', 'weight'), + ), + ); + + foreach ($this->load() as $entity) { + $form['entities'][$entity->id()] = $this->buildRow($entity); + } + + $form['actions']['#type'] = 'actions'; + $form['actions']['submit'] = array( + '#type' => 'submit', + '#value' => t('Save order'), + '#button_type' => 'primary', + ); + + return $form; + } + + /** + * {@inheritdoc} + */ + public function validateForm(array &$form, array &$form_state) { + // No validation. + } + + /** + * {@inheritdoc} + */ public function submitForm(array &$form, array &$form_state) { - parent::submitForm($form, $form_state); + $values = $form_state['values']['entities']; + + $entities = entity_load_multiple($this->entityType, array_keys($values)); + foreach ($values as $id => $value) { + if (isset($entities[$id]) && $value['weight'] != $entities[$id]->get('weight')) { + // Update changed weight. + $entities[$id]->set('weight', $value['weight']); + $entities[$id]->save(); + } + } drupal_set_message(t('The role settings have been updated.')); } - }