diff --git a/core/modules/filter/filter.module b/core/modules/filter/filter.module index 873e7d27..245087e 100644 --- a/core/modules/filter/filter.module +++ b/core/modules/filter/filter.module @@ -135,9 +135,11 @@ function filter_menu() { 'type' => MENU_LOCAL_ACTION, ); $items['admin/config/content/formats/manage/%'] = array( + 'title callback' => 'filter_admin_format_title', + 'title arguments' => array(5), 'route_name' => 'filter_format_edit', ); - $items['admin/config/content/formats/manage/%filter_format/disable'] = array( + $items['admin/config/content/formats/manage/%/disable'] = array( 'title' => 'Disable text format', 'route_name' => 'filter_admin_disable', ); @@ -184,16 +186,15 @@ function filter_format_exists($format_id) { /** * Displays a text format form title. * - * @param object $format_id - * A format object. + * @param string $format_id + * A format ID. * * @return string * The name of the format. - * - * @see filter_menu() */ -function filter_admin_format_title($format) { - return $format->name; +function filter_admin_format_title($format_id) { + $format = filter_format_load($format_id); + return $format->label(); } /** diff --git a/core/modules/filter/lib/Drupal/filter/FilterFormatEditFormController.php b/core/modules/filter/lib/Drupal/filter/FilterFormatEditFormController.php index 695239d..09a62dd 100644 --- a/core/modules/filter/lib/Drupal/filter/FilterFormatEditFormController.php +++ b/core/modules/filter/lib/Drupal/filter/FilterFormatEditFormController.php @@ -7,6 +7,8 @@ namespace Drupal\filter; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; + /** * Provides a form controller for adding a filter format. */ @@ -16,6 +18,10 @@ class FilterFormatEditFormController extends FilterFormatFormControllerBase { * {@inheritdoc} */ public function form(array $form, array &$form_state) { + if (!$this->entity->status()) { + throw new NotFoundHttpException(); + } + drupal_set_title($this->entity->label()); $form = parent::form($form, $form_state); $form['roles']['#default_value'] = array_keys(filter_get_roles_by_format($this->entity)); diff --git a/core/modules/filter/lib/Drupal/filter/FilterFormatFormControllerBase.php b/core/modules/filter/lib/Drupal/filter/FilterFormatFormControllerBase.php index 0602ad8..d9fc159 100644 --- a/core/modules/filter/lib/Drupal/filter/FilterFormatFormControllerBase.php +++ b/core/modules/filter/lib/Drupal/filter/FilterFormatFormControllerBase.php @@ -10,6 +10,7 @@ use Drupal\Core\Config\ConfigFactory; use Drupal\Core\Entity\EntityControllerInterface; use Drupal\Core\Entity\EntityFormController; +use Drupal\Core\Entity\Query\QueryFactory; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -25,10 +26,18 @@ protected $configFactory; /** + * The entity query factory. + * + * @var \Drupal\Core\Entity\Query\QueryFactory + */ + protected $queryFactory; + + /** * Constructs a new FilterFormatFormControllerBase. */ - public function __construct(ConfigFactory $config_factory) { + public function __construct(ConfigFactory $config_factory, QueryFactory $query_factory) { $this->configFactory = $config_factory; + $this->queryFactory = $query_factory; } /** @@ -36,7 +45,8 @@ public function __construct(ConfigFactory $config_factory) { */ public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) { return new static( - $container->get('config.factory') + $container->get('config.factory'), + $container->get('entity.query') ); } @@ -186,6 +196,14 @@ public function validate(array $form, array &$form_state) { // Ensure that the values to be saved later are exactly the ones validated. form_set_value($form['format'], $format_format, $form_state); form_set_value($form['name'], $format_name, $form_state); + + $format_exists = $this->queryFactory + ->get('filter_format') + ->condition('name', $format_name) + ->execute(); + if ($format_exists) { + form_set_error('name', t('Text format names must be unique. A format named %name already exists.', array('%name' => $format_name))); + } } /**