diff --git a/core/modules/filter/filter.module b/core/modules/filter/filter.module index 7e83c2c..2a9e544 100644 --- a/core/modules/filter/filter.module +++ b/core/modules/filter/filter.module @@ -545,13 +545,7 @@ function filter_fallback_format_title() { * An array of filter formats. */ function filter_get_filters() { - $filters = &drupal_static(__FUNCTION__, array()); - - if (empty($filters)) { - $filters = drupal_container()->get('plugin.manager.filter')->getDefinitions(); - } - - return $filters; + return drupal_container()->get('plugin.manager.filter')->getDefinitions(); } /** diff --git a/core/modules/filter/lib/Drupal/filter/Plugin/FilterBag.php b/core/modules/filter/lib/Drupal/filter/FilterBag.php similarity index 82% rename from core/modules/filter/lib/Drupal/filter/Plugin/FilterBag.php rename to core/modules/filter/lib/Drupal/filter/FilterBag.php index 71788fc..a049ebb 100644 --- a/core/modules/filter/lib/Drupal/filter/Plugin/FilterBag.php +++ b/core/modules/filter/lib/Drupal/filter/FilterBag.php @@ -2,12 +2,13 @@ /** * @file - * Contains \Drupal\filter\Plugin\FilterBag. + * Contains \Drupal\filter\FilterBag. */ -namespace Drupal\filter\Plugin; +namespace Drupal\filter; use Drupal\Component\Plugin\PluginBag; +use Drupal\Component\Plugin\Exception\PluginException; use Drupal\filter\Plugin\Core\Entity\FilterFormat; use Drupal\Component\Plugin\PluginManagerInterface; @@ -41,7 +42,7 @@ class FilterBag extends PluginBag { public function __construct(FilterFormat $format, PluginManagerInterface $manager) { $this->format = $format; $this->manager = $manager; - $this->instanceIDs = drupal_map_assoc(array_keys($manager->getDefinitions())); + $this->instanceIDs = $manager->getDefinitions(); } /** @@ -60,6 +61,9 @@ protected function initializePlugin($instance_id) { } $this->pluginInstances[$instance_id] = $this->manager->createInstance($instance_id, $filter, $this->format); } + else { + throw new PluginException(t("Invalid filter '@filter' for format '@format'.", array('@filter' => $instance_id, '@format' => $this->format->label()))); + } } } diff --git a/core/modules/filter/lib/Drupal/filter/FilterFormatStorageController.php b/core/modules/filter/lib/Drupal/filter/FilterFormatStorageController.php index ce67a92..f696695 100644 --- a/core/modules/filter/lib/Drupal/filter/FilterFormatStorageController.php +++ b/core/modules/filter/lib/Drupal/filter/FilterFormatStorageController.php @@ -9,6 +9,7 @@ use Drupal\Core\Config\Entity\ConfigStorageController; use Drupal\Core\Entity\EntityInterface; +use Drupal\Component\Utility\NestedArray; /** * Defines the storage controller class for Filter Format entities. @@ -24,54 +25,37 @@ protected function preSave(EntityInterface $entity) { $entity->name = trim($entity->label()); $entity->cache = _filter_format_is_cacheable($entity); - if (!isset($entity->filters)) { - $entity->filters = array(); - } - // Clear out invalid entries, including 'status' and 'order' from tabledrag. - else { - $entity->filters = array_filter($entity->filters); - } - - // Clear out any instances to ensure they are rebuilt. + // Clear out the FilterBag so that the list of available filters is rebuilt. $entity->filterPlugins->clear(); + // All available filters are saved for each format, in order to retain all + // filter properties regardless of whether a filter is currently enabled + // or not, since some filters require extensive configuration. $filter_info = filter_get_filters(); - $entity->filters = array_intersect_key($entity->filters, $filter_info); + $entity->filters += array_fill_keys(array_keys($filter_info), array()); + foreach ($filter_info as $name => $filter) { // Merge the actual filter definition into the filter default definition. $defaults = array( - 'module' => $filter['module'], // The filter ID has to be temporarily injected into the properties, in // order to sort all filters below. // @todo Rethink filter sorting to remove dependency on filter IDs. - 'name' => $name, - // Unless explicitly enabled, all filters are disabled by default. - 'status' => 0, - // If no explicit weight was defined for a filter, assign either the - // default weight defined in hook_filter_info() or the default of 0 by - // filter_get_filters(). + 'id' => $filter['id'], + 'status' => $filter['status'], 'weight' => $filter['weight'], 'settings' => $filter['default_settings'], ); - // All available filters are saved for each format, in order to retain all - // filter properties regardless of whether a filter is currently enabled - // or not, since some filters require extensive configuration. - // @todo Do not save disabled filters whose properties are identical to - // all default properties. - if (!isset($entity->filters[$name])) { - $entity->filters[$name] = array(); - } - $entity->filters[$name] += $defaults; - // The module definition from hook_filter_info() always takes precedence - // and needs to be updated in case it changes. + $entity->filters[$name] = NestedArray::mergeDeep($entity->filters[$name], $defaults); + // The module definition from the filter definition always takes + // precedence and needs to be updated in case it changes. $entity->filters[$name]['module'] = $filter['module']; } // Sort all filters. uasort($entity->filters, 'Drupal\filter\Plugin\Core\Entity\FilterFormat::sortFilters'); - // Remove the 'name' property from all filters that was added above. + // Remove the 'id' property from all filters that was added above. foreach ($entity->filters as &$filter) { - unset($filter['name']); + unset($filter['id']); } } diff --git a/core/modules/filter/lib/Drupal/filter/Plugin/Core/Entity/FilterFormat.php b/core/modules/filter/lib/Drupal/filter/Plugin/Core/Entity/FilterFormat.php index 50b130a..be96ca6 100644 --- a/core/modules/filter/lib/Drupal/filter/Plugin/Core/Entity/FilterFormat.php +++ b/core/modules/filter/lib/Drupal/filter/Plugin/Core/Entity/FilterFormat.php @@ -10,7 +10,7 @@ use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; -use Drupal\filter\Plugin\FilterBag; +use Drupal\filter\FilterBag; /** * Represents a text format. @@ -121,7 +121,7 @@ class FilterFormat extends ConfigEntityBase { /** * @todo. * - * @var \Drupal\filter\Plugin\FilterBag + * @var \Drupal\filter\FilterBag */ public $filterPlugins; @@ -156,7 +156,7 @@ public static function sortFilters(array $a, array $b) { if ($a['module'] != $b['module']) { return strnatcasecmp($a['module'], $b['module']); } - return strnatcasecmp($a['name'], $b['name']); + return strnatcasecmp($a['id'], $b['id']); } /** diff --git a/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterAutoP.php b/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterAutoP.php index b23643c..fcd4091 100644 --- a/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterAutoP.php +++ b/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterAutoP.php @@ -26,7 +26,7 @@ class FilterAutoP extends FilterBase { /** * Overrides \Drupal\filter\Plugin\filter\filter\FilterBase::tips(). */ - public function tips($filter, $long = FALSE) { + public function tips($long = FALSE) { if ($long) { return t('Lines and paragraphs are automatically recognized. The <br /> line break, <p> paragraph and </p> close paragraph tags are inserted automatically. If paragraphs are not recognized simply add a couple blank lines.'); } @@ -38,7 +38,7 @@ public function tips($filter, $long = FALSE) { /** * Implements \Drupal\filter\Plugin\filter\filter\FilterInterface::process(). */ - public function process($text, $filter, $langcode, $cache, $cache_id) { + public function process($text, $langcode, $cache, $cache_id) { return _filter_autop($text); } diff --git a/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterBase.php b/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterBase.php index ae10380..0427572 100644 --- a/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterBase.php +++ b/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterBase.php @@ -76,7 +76,7 @@ public static function sort($a, $b) { /** * Implements \Drupal\filter\Plugin\filter\filter\FilterInterface::tips(). */ - public function tips($filter, $long = FALSE) { + public function tips($long = FALSE) { } /** @@ -89,7 +89,7 @@ public function settingsForm(array $form, array &$form_state) { /** * Implements \Drupal\filter\Plugin\filter\filter\FilterInterface::prepare(). */ - public function prepare($text, $filter, $langcode, $cache, $cache_id) { + public function prepare($text, $langcode, $cache, $cache_id) { return $text; } diff --git a/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterHtml.php b/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterHtml.php index fa45c67..e656b28 100644 --- a/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterHtml.php +++ b/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterHtml.php @@ -32,10 +32,10 @@ class FilterHtml extends FilterBase { /** * Overrides \Drupal\filter\Plugin\filter\filter\FilterBase::tips(). */ - public function tips($filter, $long = FALSE) { + public function tips($long = FALSE) { global $base_url; - if (!($allowed_html = $filter->settings['allowed_html'])) { + if (!($allowed_html = $this->settings['allowed_html'])) { return; } $output = t('Allowed HTML tags: @tags', array('@tags' => $allowed_html)); @@ -44,7 +44,7 @@ public function tips($filter, $long = FALSE) { } $output = '

' . $output . '

'; - if (!$filter->settings['filter_html_help']) { + if (!$this->settings['filter_html_help']) { return $output; } @@ -154,8 +154,8 @@ public function settingsForm(array $form, array &$form_state) { /** * Implements \Drupal\filter\Plugin\filter\filter\FilterInterface::process(). */ - public function process($text, $filter, $langcode, $cache, $cache_id) { - return _filter_html($text, $filter); + public function process($text, $langcode, $cache, $cache_id) { + return _filter_html($text, $this); } } diff --git a/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterHtmlCorrector.php b/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterHtmlCorrector.php index e885cf1..f3f4303 100644 --- a/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterHtmlCorrector.php +++ b/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterHtmlCorrector.php @@ -27,7 +27,7 @@ class FilterHtmlCorrector extends FilterBase { /** * Implements \Drupal\filter\Plugin\filter\filter\FilterInterface::process(). */ - public function process($text, $filter, $langcode, $cache, $cache_id) { + public function process($text, $langcode, $cache, $cache_id) { return _filter_htmlcorrector($text); } diff --git a/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterHtmlEscape.php b/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterHtmlEscape.php index 9469744..5c0a4cb 100644 --- a/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterHtmlEscape.php +++ b/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterHtmlEscape.php @@ -27,14 +27,14 @@ class FilterHtmlEscape extends FilterBase { /** * Overrides \Drupal\filter\Plugin\filter\filter\FilterBase::tips(). */ - public function tips($filter, $long = FALSE) { + public function tips($long = FALSE) { return t('No HTML tags allowed.'); } /** * Implements \Drupal\filter\Plugin\filter\filter\FilterInterface::process(). */ - public function process($text, $filter, $langcode, $cache, $cache_id) { + public function process($text, $langcode, $cache, $cache_id) { return _filter_html_escape($text); } diff --git a/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterHtmlImageSecure.php b/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterHtmlImageSecure.php index f16b292..3d5c282 100644 --- a/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterHtmlImageSecure.php +++ b/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterHtmlImageSecure.php @@ -28,14 +28,14 @@ class FilterHtmlImageSecure extends FilterBase { /** * Overrides \Drupal\filter\Plugin\filter\filter\FilterBase::tips(). */ - public function tips($filter, $long = FALSE) { + public function tips($long = FALSE) { return t('Only images hosted on this site may be used in <img> tags.'); } /** * Implements \Drupal\filter\Plugin\filter\filter\FilterInterface::process(). */ - public function process($text, $filter, $langcode, $cache, $cache_id) { + public function process($text, $langcode, $cache, $cache_id) { return _filter_html_image_secure_process($text); } diff --git a/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterInterface.php b/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterInterface.php index 754f1d9..898c4d6 100644 --- a/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterInterface.php +++ b/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterInterface.php @@ -20,8 +20,6 @@ * A filter's tips should be informative and to the point. Short tips are * preferably one-liners. * - * @param \stdClass $filter - * An object representing the filter. * @param bool $long * Whether this callback should return a short tip to display in a form * (FALSE), or whether a more elaborate filter tips should be returned for @@ -30,7 +28,7 @@ * @return string|null * Translated text to display as a tip, or NULL if this filter has no tip. */ - public function tips($filter, $long = FALSE); + public function tips($long = FALSE); /** * Generates a filter's settings form. @@ -53,7 +51,7 @@ public function tips($filter, $long = FALSE); * * @return array * An array of form elements defining settings for the filter. Array keys - * should match the array keys in $filter->settings and $defaults. + * should match the array keys in $this->settings and $defaults. */ public function settingsForm(array $form, array &$form_state); @@ -66,8 +64,6 @@ public function settingsForm(array $form, array &$form_state); * * @param string $text * The text string to be filtered. - * @param \stdClass $filter - * The filter object containing settings for the given format. * @param string $langcode * The language code of the text to be filtered. * @param bool $cache @@ -79,15 +75,13 @@ public function settingsForm(array $form, array &$form_state); * @return string * The prepared, escaped text. */ - public function prepare($text, $filter, $langcode, $cache, $cache_id); + public function prepare($text, $langcode, $cache, $cache_id); /** * Performs the filter processing. * * @param string $text * The text string to be filtered. - * @param \stdClass $filter - * The filter object containing settings for the given format. * @param string $langcode * The language code of the text to be filtered. * @param bool $cache @@ -99,6 +93,6 @@ public function prepare($text, $filter, $langcode, $cache, $cache_id); * @return string * The filtered text. */ - public function process($text, $filter, $langcode, $cache, $cache_id); + public function process($text, $langcode, $cache, $cache_id); } diff --git a/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterUrl.php b/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterUrl.php index 70d12c3..aafff10 100644 --- a/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterUrl.php +++ b/core/modules/filter/lib/Drupal/filter/Plugin/filter/filter/FilterUrl.php @@ -29,7 +29,7 @@ class FilterUrl extends FilterBase { /** * Overrides \Drupal\filter\Plugin\filter\filter\FilterBase::tips(). */ - public function tips($filter, $long = FALSE) { + public function tips($long = FALSE) { return t('Web page addresses and e-mail addresses turn into links automatically.'); } @@ -51,8 +51,8 @@ public function settingsForm(array $form, array &$form_state) { /** * Implements \Drupal\filter\Plugin\filter\filter\FilterInterface::process(). */ - public function process($text, $filter, $langcode, $cache, $cache_id) { - return _filter_url($text, $filter); + public function process($text, $langcode, $cache, $cache_id) { + return _filter_url($text, $this); } } diff --git a/core/modules/filter/tests/filter_test/lib/Drupal/filter_test/Plugin/filter/filter/FilterTestReplace.php b/core/modules/filter/tests/filter_test/lib/Drupal/filter_test/Plugin/filter/filter/FilterTestReplace.php index 109e39f..88699fd 100644 --- a/core/modules/filter/tests/filter_test/lib/Drupal/filter_test/Plugin/filter/filter/FilterTestReplace.php +++ b/core/modules/filter/tests/filter_test/lib/Drupal/filter_test/Plugin/filter/filter/FilterTestReplace.php @@ -27,9 +27,9 @@ class FilterTestReplace extends FilterBase { /** * Implements \Drupal\filter\Plugin\filter\filter\FilterInterface::process(). */ - public function process($text, $filter, $langcode, $cache, $cache_id) { + public function process($text, $langcode, $cache, $cache_id) { $text = array(); - $text[] = 'Filter: ' . $filter->title . ' (' . $filter->name . ')'; + $text[] = 'Filter: ' . $this->title . ' (' . $this->name . ')'; $text[] = 'Format: ' . $this->format->name . ' (' . $this->format->format . ')'; $text[] = 'Language: ' . $langcode; $text[] = 'Cache: ' . ($cache ? 'Enabled' : 'Disabled'); diff --git a/core/modules/filter/tests/filter_test/lib/Drupal/filter_test/Plugin/filter/filter/FilterTestUncacheable.php b/core/modules/filter/tests/filter_test/lib/Drupal/filter_test/Plugin/filter/filter/FilterTestUncacheable.php index 32909a0..6c946bb 100644 --- a/core/modules/filter/tests/filter_test/lib/Drupal/filter_test/Plugin/filter/filter/FilterTestUncacheable.php +++ b/core/modules/filter/tests/filter_test/lib/Drupal/filter_test/Plugin/filter/filter/FilterTestUncacheable.php @@ -28,7 +28,7 @@ class FilterTestUncacheable extends FilterBase { /** * Implements \Drupal\filter\Plugin\filter\filter\FilterInterface::process(). */ - public function process($text, $filter, $langcode, $cache, $cache_id) { + public function process($text, $langcode, $cache, $cache_id) { return $text; } diff --git a/core/modules/php/lib/Drupal/php/Plugin/filter/filter/Php.php b/core/modules/php/lib/Drupal/php/Plugin/filter/filter/Php.php index 1fa0e2e..8753b2c 100644 --- a/core/modules/php/lib/Drupal/php/Plugin/filter/filter/Php.php +++ b/core/modules/php/lib/Drupal/php/Plugin/filter/filter/Php.php @@ -28,7 +28,7 @@ class Php extends FilterBase { /** * Overrides \Drupal\filter\Plugin\filter\filter\FilterBase::tips(). */ - public function tips($filter, $long = FALSE) { + public function tips($long = FALSE) { global $base_url; if ($long) { $output = '

' . t('Using custom PHP code') . '

'; @@ -69,7 +69,7 @@ public function tips($filter, $long = FALSE) { /** * Implements \Drupal\filter\Plugin\filter\filter\FilterInterface::process(). */ - public function process($text, $filter, $langcode, $cache, $cache_id) { + public function process($text, $langcode, $cache, $cache_id) { return php_eval($text); }