commit c607d8d750c83ed6d2e9a483d9cfb2c8a7224c9f Author: Bart Feenstra Date: Mon Oct 14 11:09:30 2013 +0200 foo diff --git a/core/lib/Drupal/Core/Path/AliasManager.php b/core/lib/Drupal/Core/Path/AliasManager.php index 72e5707..b2d2d7b 100644 --- a/core/lib/Drupal/Core/Path/AliasManager.php +++ b/core/lib/Drupal/Core/Path/AliasManager.php @@ -312,4 +312,23 @@ protected function pathAliasWhitelistRebuild($source = NULL) { } $this->whitelist->clear(); } + + /** + * Checks if a path alias exists. + * + * @param int $pid + * Path ID. + * @param string $alias + * Alias to check. + * @param string $langcode + * The language code. + * + * @return bool + * TRUE if alias exists, false otherwise. + */ + public function checkAliasExists($pid, $alias, $langcode) { + $query = 'SELECT pid FROM {url_alias} WHERE pid != :pid AND alias = :alias AND langcode = :langcode LIMIT 1'; + return (bool) $this->connection->query($query, array(':pid' => $pid, ':alias' => $alias, ':langcode' => $langcode))->fetchField(); + } + } diff --git a/core/modules/path/lib/Drupal/path/Controller/PathController.php b/core/modules/path/lib/Drupal/path/Controller/PathController.php index a8fae4a..1302854 100644 --- a/core/modules/path/lib/Drupal/path/Controller/PathController.php +++ b/core/modules/path/lib/Drupal/path/Controller/PathController.php @@ -7,34 +7,158 @@ namespace Drupal\path\Controller; +use Drupal\Core\Controller\ControllerBase; +use Drupal\Core\Database\Connection; +use Drupal\Core\Language\Language; +use Drupal\Core\Path\AliasManagerInterface; +use Drupal\Component\Utility\Unicode; +use Drupal\path\Form\PathAdminFilterForm; +use Drupal\Core\DependencyInjection\ContainerInjectionInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; + /** * Controller routines for path routes. */ -class PathController { +class PathController extends ControllerBase implements ContainerInjectionInterface { + + /** + * The connection service. + * + * @var \Drupal\Core\Database\Connection + */ + protected $connection; /** - * @todo Remove path_admin_overview(). + * The alias service. + * + * @var \Drupal\Core\Path\AliasManagerInterface */ - public function adminOverview($keys = NULL) { - module_load_include('admin.inc', 'path'); - return path_admin_overview($keys); + protected $aliasManager; + + /** + * Constructs a PathController object. + * + * @param \Drupal\Core\Database\Connection $connection + * The database connection service. + * @param \Drupal\Core\Path\AliasManagerInterface $alias_manager + * The path alias manager service. + */ + public function __construct(Connection $connection, AliasManagerInterface $alias_manager ) { + $this->connection = $connection; + $this->aliasManager = $alias_manager; } /** - * @todo Remove path_admin_edit(). + * {@inheritdoc} */ - public function adminEdit($path) { - $path = path_load($path); - module_load_include('admin.inc', 'path'); - return path_admin_edit($path); + public static function create(ContainerInterface $container) { + return new static( + $container->get('database'), + $container->get('path.alias_manager') + ); } /** - * @todo Remove path_admin_edit(). + * The admin overview. + * + * When filter key passed, perform a standard search on the given key, + * and return the list of matching URL aliases. + * + * @param string $alias + * Filter key. + * + * @return array + * Returns a listing of all defined URL aliases. */ - public function adminAdd() { - module_load_include('admin.inc', 'path'); - return path_admin_edit(); + public function adminOverview($alias = NULL) { + // @todo Implement the session service: http://drupal.org/node/1858196 + if (!empty($_SESSION['path_admin_filter_form'])) { + $alias = $_SESSION['path_admin_filter_form']; + } + // Add the filter form above the overview table. + $build['path_admin_filter_form'] = drupal_get_form(new PathAdminFilterForm(), $alias); + + // Enable language column if language.module is enabled or if we have any + // alias with a language. + $query = $this->connection->select('url_alias', 'u') + ->fields('u', array('pid')) + ->condition('langcode', Language::LANGCODE_NOT_SPECIFIED, '<>') + ->range(0,1); + $alias_exists = (bool) $query->execute()->fetchField(); + $multilanguage = ($this->moduleHandler()->moduleExists('language') || $alias_exists); + + $header = array(); + $header[] = array('data' => $this->t('Alias'), 'field' => 'alias', 'sort' => 'asc'); + $header[] = array('data' => $this->t('System'), 'field' => 'source'); + if ($multilanguage) { + $header[] = array('data' => $this->t('Language'), 'field' => 'langcode'); + } + $header[] = $this->t('Operations'); + + $query = $this->connection->select('url_alias') + ->extend('\Drupal\Core\Database\Query\PagerSelectExtender') + ->extend('\Drupal\Core\Database\Query\TableSortExtender'); + if ($alias) { + // Replace wildcards with PDO wildcards. + $query->condition('alias', '%' . preg_replace('!\*+!', '%', $alias) . '%', 'LIKE'); + } + $result = $query + ->fields('url_alias') + ->orderByHeader($header) + ->limit(50) + ->execute(); + + $rows = array(); + $destination = drupal_get_destination(); + foreach ($result as $data) { + $row = array(); + $row['data']['alias'] = l(Unicode::truncate($data->alias, 50, FALSE, TRUE), $data->source, array( + 'attributes' => array('title' => $data->alias), + )); + $row['data']['source'] = l(Unicode::truncate($data->source, 50, FALSE, TRUE), $data->source, array( + 'alias' => TRUE, + 'attributes' => array('title' => $data->source), + )); + if ($multilanguage) { + $row['data']['language_name'] = language_name($data->langcode); + } + + $operations = array(); + $operations['edit'] = array( + 'title' => $this->t('edit'), + 'href' => "admin/config/search/path/edit/$data->pid", + 'query' => $destination, + ); + $operations['delete'] = array( + 'title' => $this->t('delete'), + 'href' => "admin/config/search/path/delete/$data->pid", + 'query' => $destination, + ); + $row['data']['operations'] = array( + 'data' => array( + '#type' => 'operations', + '#links' => $operations, + ), + ); + + // If the system path maps to a different URL alias, highlight this table + // row to let the user know of old aliases. + if ($data->alias != $this->aliasManager->getPathAlias($data->source, $data->langcode)) { + $row['class'] = array('warning'); + } + + $rows[] = $row; + } + + $build['path_table'] = array( + '#theme' => 'table', + '#header' => $header, + '#rows' => $rows, + '#empty' => $this->t('No URL aliases available. Add URL alias.', array('@link' => $this->urlGenerator()->generate('path.admin_add'))), + ); + $build['path_pager'] = array('#theme' => 'pager'); + + return $build; } } diff --git a/core/modules/path/lib/Drupal/path/Form/EditForm.php b/core/modules/path/lib/Drupal/path/Form/EditForm.php new file mode 100644 index 0000000..45b0604 --- /dev/null +++ b/core/modules/path/lib/Drupal/path/Form/EditForm.php @@ -0,0 +1,215 @@ +path = $path; + $this->moduleHandler = $module_handler; + $this->aliasManager = $alias_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('path.crud'), + $container->get('module_handler'), + $container->get('path.alias_manager') + ); + } + + /** + * {@inheritdoc} + */ + public function getFormID() { + return 'path_alias_edit'; + } + + /** + * Form constructor. + * + * @param array $form + * An associative array containing the structure of the form. + * @param array $form_state + * An associative array containing the current state of the form. + * @param int $pid + * Optional path id. Can be omitted when adding a new path alias. + * + * @return array + * The form structure. + */ + public function buildForm(array $form, array &$form_state, $pid = NULL) { + $path_alias = $this->path->load(array('pid' => $pid)); + // If we do not have an alias yet we are adding a new one. + $form['#title'] = !empty($path_alias) ? $path_alias['alias'] : $this->t('Add alias'); + $form['source'] = array( + '#type' => 'textfield', + '#title' => $this->t('Existing system path'), + '#default_value' => $path_alias['source'], + '#maxlength' => 255, + '#size' => 45, + '#description' => $this->t('Specify the existing path you wish to alias. For example: node/28, forum/1, taxonomy/term/1.'), + '#field_prefix' => $this->urlGenerator()->generateFromPath(NULL, array('absolute' => TRUE)), + '#required' => TRUE, + ); + $form['alias'] = array( + '#type' => 'textfield', + '#title' => $this->t('Path alias'), + '#default_value' => $path_alias['alias'], + '#maxlength' => 255, + '#size' => 45, + '#description' => $this->t('Specify an alternative path by which this data can be accessed. For example, type "about" when writing an about page. Use a relative path and don\'t add a trailing slash or the URL alias won\'t work.'), + '#field_prefix' => $this->urlGenerator()->generateFromPath(NULL, array('absolute' => TRUE)), + '#required' => TRUE, + ); + + // A hidden value unless language.module is enabled. + if ($this->moduleHandler->moduleExists('language')) { + // @todo add DI for language_list https://drupal.org/node/1862202 + $languages = language_list(); + $language_options = array(); + foreach ($languages as $langcode => $language) { + $language_options[$langcode] = $language->name; + } + + $form['langcode'] = array( + '#type' => 'select', + '#title' => $this->t('Language'), + '#options' => $language_options, + '#empty_value' => Language::LANGCODE_NOT_SPECIFIED, + '#empty_option' => $this->t('- None -'), + '#default_value' => $path_alias['langcode'], + '#weight' => -10, + '#description' => $this->t('A path alias set for a specific language will always be used when displaying this page in that language, and takes precedence over path aliases set as - None -.'), + ); + } + else { + $form['langcode'] = array( + '#type' => 'value', + '#value' => $path_alias['langcode'] + ); + } + + $form['actions'] = array('#type' => 'actions'); + $form['actions']['submit'] = array( + '#type' => 'submit', + '#value' => $this->t('Save'), + ); + if ($path_alias['pid']) { + $form['pid'] = array( + '#type' => 'hidden', + '#value' => $path_alias['pid'], + ); + $form['actions']['delete'] = array( + '#type' => 'submit', + '#submit' => array(array($this, 'deleteForm')), + '#value' => $this->t('Delete'), + ); + } + + return $form; + } + + /** + * {@inheritdoc} + */ + public function validateForm(array &$form, array &$form_state) { + $pid = isset($form_state['values']['pid']) ? $form_state['values']['pid'] : 0; + $alias = $form_state['values']['alias']; + // Language is only set if language.module is enabled, otherwise save for all + // languages. + $langcode = isset($form_state['values']['langcode']) ? $form_state['values']['langcode'] : Language::LANGCODE_NOT_SPECIFIED; + $source = &$form_state['values']['source']; + $source = $this->aliasManager->getSystemPath($source, $langcode); + + $alias_exists = $this->aliasManager->checkAliasExists($pid, $alias, $langcode); + if ($alias_exists) { + form_set_error('alias', $this->t('The alias %alias is already in use in this language.', array('%alias' => $alias))); + } + if (!drupal_valid_path($source)) { + form_set_error('source', $this->t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $source))); + } + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + // Remove unnecessary values. + form_state_values_clean($form_state); + + $pid = isset($form_state['values']['pid']) ? $form_state['values']['pid'] : NULL; + $alias = $form_state['values']['alias']; + // Language is only set if language.module is enabled, otherwise save for all + // languages. + $langcode = isset($form_state['values']['langcode']) ? $form_state['values']['langcode'] : Language::LANGCODE_NOT_SPECIFIED; + $source = &$form_state['values']['source']; + $source = $this->aliasManager->getSystemPath($source, $langcode); + $this->path->save($source, $alias, $langcode, $pid); + drupal_set_message($this->t('The alias has been saved.')); + $form_state['redirect'] = 'admin/config/search/path'; + } + + /** + * {@inheritdoc} + */ + public function deleteForm(array &$form, array &$form_state) { + $pid = isset($form_state['values']['pid']) ? $form_state['values']['pid'] : NULL; + $query = $this->getRequest()->query; + $destination = array(); + if ($query->has('destination')) { + $destination = array('destination' => $query->get('destination')); + $query->remove('destination'); + } + $form_state['redirect'] = array('admin/config/search/path/delete/' . $pid, array('query' => $destination)); + } +} diff --git a/core/modules/path/lib/Drupal/path/Form/PathAdminFilterForm.php b/core/modules/path/lib/Drupal/path/Form/PathAdminFilterForm.php new file mode 100644 index 0000000..793cf93 --- /dev/null +++ b/core/modules/path/lib/Drupal/path/Form/PathAdminFilterForm.php @@ -0,0 +1,112 @@ + array('search-form'), + ); + $form['basic'] = array( + '#type' => 'details', + '#title' => $this->t('Filter aliases'), + '#attributes' => array( + 'class' => array('container-inline'), + ), + ); + $form['basic']['filter'] = array( + '#type' => 'search', + '#title' => 'Path alias', + '#title_display' => 'invisible', + '#default_value' => $alias, + '#maxlength' => 128, + '#size' => 25, + ); + $form['basic']['submit'] = array( + '#type' => 'submit', + '#validate' => array(array($this, 'validateFilter')), + '#submit' => array(array($this, 'submitFilter')), + '#value' => $this->t('Filter'), + ); + if ($alias) { + $form['basic']['reset'] = array( + '#type' => 'submit', + '#submit' => array(array($this, 'submitReset')), + '#value' => $this->t('Reset'), + ); + } + return $form; + } + + /** + * {@inheritdoc} + */ + public function validateFilter(array &$form, array &$form_state) { + if (empty($form_state['values']['filter'])) { + form_set_error('type', $this->t('You must provide a keyword something to filter by.')); + } + } + + /** + * Filters form submission handler. + * + * @param array $form + * An associative array containing the structure of the form. + * @param array $form_state + * An associative array containing the current state of the form. + */ + public function submitFilter(array &$form, array &$form_state) { + $_SESSION['path_admin_filter_form'] = trim($form_state['values']['filter']); + } + + /** + * Resets form submission handler. + * + * @param array $form + * An associative array containing the structure of the form. + * @param array $form_state + * An associative array containing the current state of the form. + */ + public function submitReset(array &$form, array &$form_state) { + $_SESSION['path_admin_filter_form'] = NULL; + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + // Empty, see self::submitFilter() and self::submitReset(). + } + +} diff --git a/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php b/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php index 63ebf66..52a6d9e 100644 --- a/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php +++ b/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php @@ -19,7 +19,7 @@ class PathLanguageTest extends PathTestBase { * * @var array */ - public static $modules = array('path', 'locale', 'content_translation'); + public static $modules = array('path', 'language', 'content_translation'); public static function getInfo() { return array( diff --git a/core/modules/path/lib/Drupal/path/Tests/PathLanguageUiTest.php b/core/modules/path/lib/Drupal/path/Tests/PathLanguageUiTest.php index 5c97eff..6cd5de6 100644 --- a/core/modules/path/lib/Drupal/path/Tests/PathLanguageUiTest.php +++ b/core/modules/path/lib/Drupal/path/Tests/PathLanguageUiTest.php @@ -17,7 +17,7 @@ class PathLanguageUiTest extends PathTestBase { * * @var array */ - public static $modules = array('path', 'locale'); + public static $modules = array('path', 'language'); public static function getInfo() { return array( diff --git a/core/modules/path/path.admin.inc b/core/modules/path/path.admin.inc deleted file mode 100644 index 4c5b3f4..0000000 --- a/core/modules/path/path.admin.inc +++ /dev/null @@ -1,326 +0,0 @@ - :langcode', 0, 1, array(':langcode' => Language::LANGCODE_NOT_SPECIFIED))->fetchField(); - $multilanguage = (module_exists('language') || $alias_exists); - - $header = array(); - $header[] = array('data' => t('Alias'), 'field' => 'alias', 'sort' => 'asc'); - $header[] = array('data' => t('System'), 'field' => 'source'); - if ($multilanguage) { - $header[] = array('data' => t('Language'), 'field' => 'langcode'); - } - $header[] = t('Operations'); - - $query = db_select('url_alias') - ->extend('Drupal\Core\Database\Query\PagerSelectExtender') - ->extend('Drupal\Core\Database\Query\TableSortExtender'); - if ($keys) { - // Replace wildcards with PDO wildcards. - $query->condition('alias', '%' . preg_replace('!\*+!', '%', $keys) . '%', 'LIKE'); - } - $result = $query - ->fields('url_alias') - ->orderByHeader($header) - ->limit(50) - ->execute(); - - $rows = array(); - $destination = drupal_get_destination(); - foreach ($result as $data) { - $row = array(); - $row['data']['alias'] = l(truncate_utf8($data->alias, 50, FALSE, TRUE), $data->source, array( - 'attributes' => array('title' => $data->alias), - )); - $row['data']['source'] = l(truncate_utf8($data->source, 50, FALSE, TRUE), $data->source, array( - 'alias' => TRUE, - 'attributes' => array('title' => $data->source), - )); - if ($multilanguage) { - $row['data']['language_name'] = language_name($data->langcode); - } - - $operations = array(); - $operations['edit'] = array( - 'title' => t('edit'), - 'href' => "admin/config/search/path/edit/$data->pid", - 'query' => $destination, - ); - $operations['delete'] = array( - 'title' => t('delete'), - 'href' => "admin/config/search/path/delete/$data->pid", - 'query' => $destination, - ); - $row['data']['operations'] = array( - 'data' => array( - '#type' => 'operations', - '#links' => $operations, - ), - ); - - // If the system path maps to a different URL alias, highlight this table - // row to let the user know of old aliases. - if ($data->alias != \Drupal::service('path.alias_manager')->getPathAlias($data->source, $data->langcode)) { - $row['class'] = array('warning'); - } - - $rows[] = $row; - } - - $build['path_table'] = array( - '#theme' => 'table', - '#header' => $header, - '#rows' => $rows, - '#empty' => t('No URL aliases available. Add URL alias.', array('@link' => url('admin/config/search/path/add'))), - ); - $build['path_pager'] = array('#theme' => 'pager'); - - return $build; -} - -/** - * Page callback: Returns a form creating or editing a path alias. - * - * @param $path - * An array containing the path ID, source, alias, and language code. - * - * @return - * A form for adding or editing a URL alias. - * - * @see path_menu() - * - * @deprecated Use \Drupal\path\Controller\PathController::adminEdit() or - * \Drupal\path\Controller\PathController::adminEdit() - */ -function path_admin_edit($path = array()) { - if ($path) { - drupal_set_title($path['alias']); - $output = drupal_get_form('path_admin_form', $path); - } - else { - $output = drupal_get_form('path_admin_form'); - } - - return $output; -} - -/** - * Form constructor for the path administration form. - * - * @param $path - * An array containing the path ID, source, alias, and language code. - * - * @ingroup forms - * @see path_admin_form_validate() - * @see path_admin_form_submit() - * @see path_admin_form_delete_submit() - */ -function path_admin_form($form, &$form_state, $path = array('source' => '', 'alias' => '', 'langcode' => Language::LANGCODE_NOT_SPECIFIED, 'pid' => NULL)) { - $form['source'] = array( - '#type' => 'textfield', - '#title' => t('Existing system path'), - '#default_value' => $path['source'], - '#maxlength' => 255, - '#size' => 45, - '#description' => t('Specify the existing path you wish to alias. For example: node/28, forum/1, taxonomy/term/1.'), - '#field_prefix' => url(NULL, array('absolute' => TRUE)), - '#required' => TRUE, - ); - $form['alias'] = array( - '#type' => 'textfield', - '#title' => t('Path alias'), - '#default_value' => $path['alias'], - '#maxlength' => 255, - '#size' => 45, - '#description' => t('Specify an alternative path by which this data can be accessed. For example, type "about" when writing an about page. Use a relative path and don\'t add a trailing slash or the URL alias won\'t work.'), - '#field_prefix' => url(NULL, array('absolute' => TRUE)), - '#required' => TRUE, - ); - - // A hidden value unless language.module is enabled. - if (module_exists('language')) { - $languages = language_list(); - foreach ($languages as $langcode => $language) { - $language_options[$langcode] = $language->name; - } - - $form['langcode'] = array( - '#type' => 'select', - '#title' => t('Language'), - '#options' => $language_options, - '#empty_value' => Language::LANGCODE_NOT_SPECIFIED, - '#empty_option' => t('- None -'), - '#default_value' => $path['langcode'], - '#weight' => -10, - '#description' => t('A path alias set for a specific language will always be used when displaying this page in that language, and takes precedence over path aliases set as - None -.'), - ); - } - else { - $form['langcode'] = array( - '#type' => 'value', - '#value' => $path['langcode'] - ); - } - - $form['actions'] = array('#type' => 'actions'); - $form['actions']['submit'] = array( - '#type' => 'submit', - '#value' => t('Save'), - ); - if ($path['pid']) { - $form['pid'] = array( - '#type' => 'hidden', - '#value' => $path['pid'], - ); - $form['actions']['delete'] = array( - '#type' => 'submit', - '#value' => t('Delete'), - '#submit' => array('path_admin_form_delete_submit'), - ); - } - - return $form; -} - -/** - * Form submission handler for the 'Delete' button on path_admin_form(). - * - * @see path_admin_form_validate() - * @see path_admin_form_submit() - */ -function path_admin_form_delete_submit($form, &$form_state) { - $destination = array(); - $query = \Drupal::request()->query; - if ($query->has('destination')) { - $destination = drupal_get_destination(); - $query->remove('destination'); - } - $form_state['redirect'] = array('admin/config/search/path/delete/' . $form_state['values']['pid'], array('query' => $destination)); -} - -/** - * Form validation handler for path_admin_form(). - * - * @see path_admin_form_submit() - * @see path_admin_form_delete_submit() - */ -function path_admin_form_validate($form, &$form_state) { - $source = &$form_state['values']['source']; - $source = \Drupal::service('path.alias_manager')->getSystemPath($source); - $alias = $form_state['values']['alias']; - $pid = isset($form_state['values']['pid']) ? $form_state['values']['pid'] : 0; - // Language is only set if language.module is enabled, otherwise save for all - // languages. - $langcode = isset($form_state['values']['langcode']) ? $form_state['values']['langcode'] : Language::LANGCODE_NOT_SPECIFIED; - - $has_alias = db_query("SELECT COUNT(alias) FROM {url_alias} WHERE pid <> :pid AND alias = :alias AND langcode = :langcode", array( - ':pid' => $pid, - ':alias' => $alias, - ':langcode' => $langcode, - )) - ->fetchField(); - - if ($has_alias) { - form_set_error('alias', t('The alias %alias is already in use in this language.', array('%alias' => $alias))); - } - if (!drupal_valid_path($source)) { - form_set_error('source', t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $source))); - } -} - -/** - * Form submission handler for path_admin_form(). - * - * @see path_admin_form_validate() - * @see path_admin_form_delete_submit() - */ -function path_admin_form_submit($form, &$form_state) { - // Remove unnecessary values. - form_state_values_clean($form_state); - - $pid = isset($form_state['values']['pid']) ? $form_state['values']['pid'] : 0; - $source = &$form_state['values']['source']; - $source = \Drupal::service('path.alias_manager')->getSystemPath($source); - $alias = $form_state['values']['alias']; - // Language is only set if language.module is enabled, otherwise save for all - // languages. - $langcode = isset($form_state['values']['langcode']) ? $form_state['values']['langcode'] : Language::LANGCODE_NOT_SPECIFIED; - - \Drupal::service('path.crud')->save($source, $alias, $langcode, $pid); - - drupal_set_message(t('The alias has been saved.')); - $form_state['redirect'] = 'admin/config/search/path'; -} - -/** - * Form constructor for the path admin overview filter form. - * - * @ingroup forms - * @see path_admin_filter_form_submit_filter() - * @see path_admin_filter_form_submit_reset() - */ -function path_admin_filter_form($form, &$form_state, $keys = '') { - $form['#attributes'] = array('class' => array('search-form')); - $form['basic'] = array('#type' => 'details', - '#title' => t('Filter aliases'), - '#attributes' => array('class' => array('container-inline')), - ); - $form['basic']['filter'] = array( - '#type' => 'search', - '#title' => 'Path alias', - '#title_display' => 'invisible', - '#default_value' => $keys, - '#maxlength' => 128, - '#size' => 25, - ); - $form['basic']['submit'] = array( - '#type' => 'submit', - '#value' => t('Filter'), - '#submit' => array('path_admin_filter_form_submit_filter'), - ); - if ($keys) { - $form['basic']['reset'] = array( - '#type' => 'submit', - '#value' => t('Reset'), - '#submit' => array('path_admin_filter_form_submit_reset'), - ); - } - return $form; -} - -/** - * Form submission handler for the path_admin_filter_form() Filter button. - * - * @see path_admin_filter_form_submit_reset() - */ -function path_admin_filter_form_submit_filter($form, &$form_state) { - $form_state['redirect'] = 'admin/config/search/path/list/' . trim($form_state['values']['filter']); -} - -/** - * Form submission handler for the path_admin_filter_form() Reset button. - * - * @see path_admin_filter_form_submit_filter() - */ -function path_admin_filter_form_submit_reset($form, &$form_state) { - $form_state['redirect'] = 'admin/config/search/path/list'; -} diff --git a/core/modules/path/path.local_actions.yml b/core/modules/path/path.local_actions.yml new file mode 100644 index 0000000..9c58984 --- /dev/null +++ b/core/modules/path/path.local_actions.yml @@ -0,0 +1,5 @@ +path.admin_add: + route_name: path.admin_add + title: 'Add alias' + appears_on: + - path.admin_overview diff --git a/core/modules/path/path.local_tasks.yml b/core/modules/path/path.local_tasks.yml new file mode 100644 index 0000000..15e1990 --- /dev/null +++ b/core/modules/path/path.local_tasks.yml @@ -0,0 +1,9 @@ +path.admin_overview_tab: + route_name: path.admin_overview + title: 'URL aliases' + tab_root_id: path.admin_overview_tab + +path.admin_add_tab: + route_name: path.admin_add + title: 'Add alias' + tab_root_id: path.admin_overview_tab diff --git a/core/modules/path/path.module b/core/modules/path/path.module index 1cdcc49..3ddc82d 100644 --- a/core/modules/path/path.module +++ b/core/modules/path/path.module @@ -62,23 +62,6 @@ function path_menu() { 'route_name' => 'path.admin_overview', 'weight' => -5, ); - $items['admin/config/search/path/list'] = array( - 'title' => 'List', - 'type' => MENU_DEFAULT_LOCAL_TASK, - ); - $items['admin/config/search/path/edit/%path'] = array( - 'title' => 'Edit alias', - 'route_name' => 'path.admin_edit', - ); - $items['admin/config/search/path/delete/%path'] = array( - 'title' => 'Delete alias', - 'route_name' => 'path.delete', - ); - $items['admin/config/search/path/add'] = array( - 'title' => 'Add alias', - 'route_name' => 'path.admin_add', - 'type' => MENU_LOCAL_ACTION, - ); return $items; } diff --git a/core/modules/path/path.routing.yml b/core/modules/path/path.routing.yml index a6712e2..858c856 100644 --- a/core/modules/path/path.routing.yml +++ b/core/modules/path/path.routing.yml @@ -1,16 +1,8 @@ -path.delete: - path: '/admin/config/search/path/delete/{pid}' - defaults: - _form: '\Drupal\path\Form\DeleteForm' - requirements: - _permission: 'administer url aliases' - path.admin_overview: - path: '/admin/config/search/path/{keys}' + path: '/admin/config/search/path/' defaults: _title: 'URL aliases' _content: '\Drupal\path\Controller\PathController::adminOverview' - keys: NULL requirements: _permission: 'administer url aliases' @@ -18,14 +10,20 @@ path.admin_add: path: '/admin/config/search/path/add' defaults: _title: 'Add alias' - _content: '\Drupal\path\Controller\PathController::adminAdd' + _form: '\Drupal\path\Form\EditForm' + requirements: + _permission: 'administer url aliases' + +path.admin_delete: + path: 'admin/config/search/path/delete/{pid}' + defaults: + _form: '\Drupal\path\Form\DeleteForm' requirements: _permission: 'administer url aliases' path.admin_edit: - path: '/admin/config/search/path/edit/{path}' + path: '/admin/config/search/path/edit/{pid}' defaults: - _title: 'Edit alias' - _content: '\Drupal\path\Controller\PathController::adminEdit' + _form: '\Drupal\path\Form\EditForm' requirements: _permission: 'administer url aliases'