diff --git a/core/includes/config.inc b/core/includes/config.inc index 20e6bb4..bfef876 100644 --- a/core/includes/config.inc +++ b/core/includes/config.inc @@ -206,6 +206,7 @@ function config_sync_changes(array $config_changes, StorageInterface $source_sto function config_import() { // Retrieve a list of differences between staging and the active configuration. $source_storage = drupal_container()->get('config.storage.staging'); + $snapshot_storage = drupal_container()->get('config.storage.snapshot'); $target_storage = drupal_container()->get('config.storage'); $config_changes = config_sync_get_changes($source_storage, $target_storage); @@ -226,6 +227,7 @@ function config_import() { try { $remaining_changes = config_import_invoke_owner($config_changes, $source_storage, $target_storage); config_sync_changes($remaining_changes, $source_storage, $target_storage); + config_import_create_snapshot($target_storage, $snapshot_storage); } catch (ConfigException $e) { watchdog_exception('config_import', $e); @@ -237,6 +239,65 @@ function config_import() { } /** + * Creates a configuration snapshot following a successful import. + * + * @param Drupal\Core\Config\StorageInterface $source_storage + * The storage to synchronize configuration from. + * @param Drupal\Core\Config\StorageInterface $target_storage + * The storage to synchronize configuration to. + */ +function config_import_create_snapshot(StorageInterface $source_storage, StorageInterface $snapshot_storage) { + $snapshot_storage->deleteAll(); + foreach ($source_storage->listAll() as $name) { + $snapshot_storage->write($name, $source_storage->read($name)); + } +} + +/** + * Resets configuration to the state of the last import. + * + * @param string $config_name + * Name of the config object to be restored. + * @param string $op + * The operation to be performed, must be one of 'change', 'create' or + * 'delete'. + * + * @return boolean + */ +function config_restore_from_snapshot($config_name, $op) { + $source_storage = drupal_container()->get('config.storage.snapshot'); + $target_storage = drupal_container()->get('config.storage'); + $config_changes = array( + 'create' => array(), + 'delete' => array(), + 'change' => array(), + ); + + if (!isset($config_changes[$op])) { + return FALSE; + } + $config_changes[$op] = array($config_name); + + if (!lock()->acquire('config_import')) { + return FALSE; + } + + $success = FALSE; + try { + $remaining_changes = config_import_invoke_owner($config_changes, $source_storage, $target_storage); + config_sync_changes($remaining_changes, $source_storage, $target_storage); + // Flush all caches and reset static variables after a successful import. + drupal_flush_all_caches(); + $success = TRUE; + } + catch (ConfigException $e) { + watchdog_exception('config_restore_from_snapshot', $e); + } + lock()->release(__FUNCTION__); + return $success; +} + +/** * Invokes MODULE_config_import() callbacks for configuration changes. * * @param array $config_changes diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 7f4b26b..ede851c 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -1806,6 +1806,11 @@ function install_finished(&$install_state) { // Will also trigger indexing of profile-supplied content or feeds. drupal_cron_run(); + // Save a snapshot of the intially installed configuration. + $active = drupal_container()->get('config.storage'); + $snapshot = drupal_container()->get('config.storage.snapshot'); + config_import_create_snapshot($active, $snapshot); + return $output; } diff --git a/core/lib/Drupal/Core/CoreBundle.php b/core/lib/Drupal/Core/CoreBundle.php index 52af901..b2700f9 100644 --- a/core/lib/Drupal/Core/CoreBundle.php +++ b/core/lib/Drupal/Core/CoreBundle.php @@ -60,6 +60,12 @@ public function build(ContainerBuilder $container) { ->register('config.storage.staging', 'Drupal\Core\Config\FileStorage') ->addArgument(config_get_config_directory(CONFIG_STAGING_DIRECTORY)); + // Register import snapshot configuration storage. + $container + ->register('config.storage.snapshot', 'Drupal\Core\Config\DatabaseStorage') + ->addArgument(new Reference('database')) + ->addArgument('config_snapshot'); + // Register the service for the default database connection. $container->register('database', 'Drupal\Core\Database\Connection') ->setFactoryClass('Drupal\Core\Database\Database') diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php index c607973..b5047c9 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php @@ -36,12 +36,12 @@ function setUp() { config('system.site')->set('page.front', 'test-page')->save(); // Create Full HTML text format. - $full_html_format = array( + $full_html_format_config = array( 'format' => 'full_html', 'name' => 'Full HTML', ); - $full_html_format = (object) $full_html_format; - filter_format_save($full_html_format); + $full_html_format = entity_create('filter_format', $full_html_format_config); + $full_html_format->save(); $this->checkPermissions(array(), TRUE); // Create and log in an administrative user having access to the Full HTML diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigCRUDTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigCRUDTest.php index a04a928..b0c7810 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigCRUDTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigCRUDTest.php @@ -27,6 +27,7 @@ public static function getInfo() { */ function testCRUD() { $storage = $this->container->get('config.storage'); + $snapshot = $this->container->get('config.storage.snapshot'); $name = 'config_test.crud'; $config = config($name); diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigImportTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigImportTest.php index 95089f7..d4328ce 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigImportTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigImportTest.php @@ -19,7 +19,7 @@ class ConfigImportTest extends DrupalUnitTestBase { * * @var array */ - public static $modules = array('config_test'); + public static $modules = array('config_test', 'system'); public static function getInfo() { return array( @@ -32,6 +32,8 @@ public static function getInfo() { function setUp() { parent::setUp(); + $this->installSchema('system', 'config_snapshot'); + config_install_default_config('module', 'config_test'); // Installing config_test's default configuration pollutes the global // variable being used for recording hook invocations by this test already, diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigSnapshotTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigSnapshotTest.php new file mode 100644 index 0000000..89ca680 --- /dev/null +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigSnapshotTest.php @@ -0,0 +1,79 @@ + 'Snapshot functionality', + 'description' => 'Config snapshot creation and updating.', + 'group' => 'Configuration', + ); + } + + /** + * Tests config snapshot creation and updating. + */ + function testSnapshot() { + $active = $this->container->get('config.storage'); + $staging = $this->container->get('config.storage.staging'); + $snapshot = $this->container->get('config.storage.snapshot'); + + $config_name = 'system.performance'; + $config_key = 'cache.page.max_age'; + $original_data = '0'; + $new_data = '10'; + + // Verify that we have an initial snapshot that matches the active + // configuration. + $this->assertFalse(config_sync_get_changes($snapshot, $active)); + + // Change a configuration value. + $config = config($config_name); + $config->set($config_key, $new_data)->save(); + $staging_data = $config->get(); + + // Verify the active configuration contains the saved value. + $this->assertIdentical(config($config_name)->get($config_key), $new_data); + + // Verify that the active and snapshot storage do not match. + $this->assertTrue(config_sync_get_changes($snapshot, $active)); + + // Reset data back to original value. + config_restore_from_snapshot($config_name, 'change'); + + // Verify that the active and snapshot storage match again. + $this->assertFalse(config_sync_get_changes($snapshot, $active)); + + // Change a configuration value in staging. + $staging->write($config_name, $staging_data); + + // Verify that active and snapshot match, and that staging doesn't match + // either of them. + $this->assertFalse(config_sync_get_changes($snapshot, $active)); + $this->assertTrue(config_sync_get_changes($snapshot, $staging)); + $this->assertTrue(config_sync_get_changes($staging, $active)); + + // Import changed data from staging to active. + config_import(); + + // Verify changed config was properly imported. + $this->assertIdentical(config($config_name)->get($config_key), $new_data); + + // Verify that a new snapshot was created which and that it matches + // the active config. + $this->assertFalse(config_sync_get_changes($snapshot, $active)); + } + +} diff --git a/core/modules/filter/filter.admin.inc b/core/modules/filter/filter.admin.inc index 3c01ac2..c7a891c 100644 --- a/core/modules/filter/filter.admin.inc +++ b/core/modules/filter/filter.admin.inc @@ -75,13 +75,12 @@ function filter_admin_overview($form) { * Form submission handler for filter_admin_overview(). */ function filter_admin_overview_submit($form, &$form_state) { + $filter_formats = filter_formats(); foreach ($form_state['values']['formats'] as $id => $data) { if (is_array($data) && isset($data['weight'])) { // Only update if this is a form element with weight. - db_update('filter_format') - ->fields(array('weight' => $data['weight'])) - ->condition('format', $id) - ->execute(); + $filter_formats[$id]->weight = $data['weight']; + $filter_formats[$id]->save(); } } filter_formats_reset(); @@ -113,10 +112,8 @@ function filter_admin_overview_submit($form, &$form_state) { function filter_admin_format_page($format = NULL) { if (!isset($format->name)) { drupal_set_title(t('Add text format')); - $format = (object) array( - 'format' => NULL, - 'name' => '', - ); + + $format = entity_create('filter_format', array()); } return drupal_get_form('filter_admin_format_form', $format); } @@ -187,88 +184,75 @@ function filter_admin_format_form($form, &$form_state, $format) { $form['roles']['#default_value'] = array($admin_role); } + // Filter status. + $form['filters']['status'] = array( + '#type' => 'item', + '#title' => t('Enabled filters'), + '#prefix' => '
-
-
- ',
- 'filter_html_help' => 1,
- 'filter_html_nofollow' => 0,
- ),
- 'tips callback' => '_filter_html_tips',
- );
- $filters['filter_autop'] = array(
- 'title' => t('Convert line breaks'),
- 'description' => t('Converts line breaks into HTML (i.e. <br> and <p>) tags.'),
- 'process callback' => '_filter_autop',
- 'tips callback' => '_filter_autop_tips',
- );
- return $filters;
-}
-
-/**
* Perform alterations on filter definitions.
*
* @param $info
- * Array of information on filters exposed by hook_filter_info()
- * implementations.
+ * Array of information on filters exposed by filter plugins.
*/
function hook_filter_info_alter(&$info) {
- // Replace the PHP evaluator process callback with an improved
- // PHP evaluator provided by a module.
- $info['php_code']['process callback'] = 'my_module_php_evaluator';
-
// Alter the default settings of the URL filter provided by core.
- $info['filter_url']['default settings'] = array(
+ $info['filter_url']['default_settings'] = array(
'filter_url_length' => 100,
);
}
/**
- * @} End of "addtogroup hooks".
- */
-
-/**
- * Settings callback for hook_filter_info().
- *
- * Note: This is not really a hook. The function name is manually specified via
- * 'settings callback' in hook_filter_info(), with this recommended callback
- * name pattern. It is called from filter_admin_format_form().
- *
- * This callback function is used to provide a settings form for filter
- * settings, for filters that need settings on a per-text-format basis. This
- * function should return the form elements for the settings; the filter
- * module will take care of saving the settings in the database.
- *
- * If the filter's behavior depends on an extensive list and/or external data
- * (e.g. a list of smileys, a list of glossary terms), then the filter module
- * can choose to provide a separate, global configuration page rather than
- * per-text-format settings. In that case, the settings callback function
- * should provide a link to the separate settings page.
- *
- * @param $form
- * The prepopulated form array of the filter administration form.
- * @param $form_state
- * The state of the (entire) configuration form.
- * @param $filter
- * The filter object containing the current settings for the given format,
- * in $filter->settings.
- * @param $format
- * The format object being configured.
- * @param $defaults
- * The default settings for the filter, as defined in 'default settings' in
- * hook_filter_info(). These should be combined with $filter->settings to
- * define the form element defaults.
- * @param $filters
- * The complete list of filter objects that are enabled for the given format.
- *
- * @return
- * An array of form elements defining settings for the filter. Array keys
- * should match the array keys in $filter->settings and $defaults.
- */
-function hook_filter_FILTER_settings($form, &$form_state, $filter, $format, $defaults, $filters) {
- $filter->settings += $defaults;
-
- $elements = array();
- $elements['nofollow'] = array(
- '#type' => 'checkbox',
- '#title' => t('Add rel="nofollow" to all links'),
- '#default_value' => $filter->settings['nofollow'],
- );
- return $elements;
-}
-
-/**
- * Prepare callback for hook_filter_info().
- *
- * Note: This is not really a hook. The function name is manually specified via
- * 'prepare callback' in hook_filter_info(), with this recommended callback
- * name pattern. It is called from check_markup().
- *
- * See hook_filter_info() for a description of the filtering process. Filters
- * should not use the 'prepare callback' step for anything other than escaping,
- * because that would short-circuit the control the user has over the order in
- * which filters are applied.
- *
- * @param $text
- * The text string to be filtered.
- * @param $filter
- * The filter object containing settings for the given format.
- * @param $format
- * The text format object assigned to the text to be filtered.
- * @param $langcode
- * The language code of the text to be filtered.
- * @param $cache
- * A Boolean indicating whether the filtered text is going to be cached in
- * {cache_filter}.
- * @param $cache_id
- * The ID of the filtered text in {cache_filter}, if $cache is TRUE.
- *
- * @return
- * The prepared, escaped text.
- */
-function hook_filter_FILTER_prepare($text, $filter, $format, $langcode, $cache, $cache_id) {
- // Escape
and
tags.
- $text = preg_replace('|(.+?)
|se', "[codefilter_code]$1[/codefilter_code]", $text);
- return $text;
-}
-
-/**
- * Process callback for hook_filter_info().
- *
- * Note: This is not really a hook. The function name is manually specified via
- * 'process callback' in hook_filter_info(), with this recommended callback
- * name pattern. It is called from check_markup().
- *
- * See hook_filter_info() for a description of the filtering process. This step
- * is where the filter actually transforms the text.
- *
- * @param $text
- * The text string to be filtered.
- * @param $filter
- * The filter object containing settings for the given format.
- * @param $format
- * The text format object assigned to the text to be filtered.
- * @param $langcode
- * The language code of the text to be filtered.
- * @param $cache
- * A Boolean indicating whether the filtered text is going to be cached in
- * {cache_filter}.
- * @param $cache_id
- * The ID of the filtered text in {cache_filter}, if $cache is TRUE.
- *
- * @return
- * The filtered text.
- */
-function hook_filter_FILTER_process($text, $filter, $format, $langcode, $cache, $cache_id) {
- $text = preg_replace('|\[codefilter_code\](.+?)\[/codefilter_code\]|se', "$1
", $text);
-
- return $text;
-}
-
-/**
- * Tips callback for hook_filter_info().
- *
- * Note: This is not really a hook. The function name is manually specified via
- * 'tips callback' in hook_filter_info(), with this recommended callback
- * name pattern. It is called from _filter_tips().
- *
- * A filter's tips should be informative and to the point. Short tips are
- * preferably one-liners.
- *
- * @param $filter
- * An object representing the filter.
- * @param $format
- * An object representing the text format the filter is contained in.
- * @param $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
- * theme_filter_tips() (TRUE).
- *
- * @return
- * Translated text to display as a tip.
- */
-function hook_filter_FILTER_tips($filter, $format, $long) {
- 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.');
- }
- else {
- return t('Lines and paragraphs break automatically.');
- }
-}
-
-/**
- * @addtogroup hooks
- * @{
- */
-
-/**
- * Perform actions when a new text format has been created.
- *
- * @param $format
- * The format object of the format being updated.
- *
- * @see hook_filter_format_update()
- * @see hook_filter_format_disable()
- */
-function hook_filter_format_insert($format) {
- mymodule_cache_rebuild();
-}
-
-/**
- * Perform actions when a text format has been updated.
- *
- * This hook allows modules to act when a text format has been updated in any
- * way. For example, when filters have been reconfigured, disabled, or
- * re-arranged in the text format.
- *
- * @param $format
- * The format object of the format being updated.
- *
- * @see hook_filter_format_insert()
- * @see hook_filter_format_disable()
- */
-function hook_filter_format_update($format) {
- mymodule_cache_rebuild();
-}
-
-/**
* Perform actions when a text format has been disabled.
*
* @param $format
* The format object of the format being disabled.
- *
- * @see hook_filter_format_insert()
- * @see hook_filter_format_update()
*/
function hook_filter_format_disable($format) {
mymodule_cache_rebuild();
diff --git a/core/modules/filter/filter.install b/core/modules/filter/filter.install
index f3c29a5..af2e6ae 100644
--- a/core/modules/filter/filter.install
+++ b/core/modules/filter/filter.install
@@ -3,108 +3,19 @@
/**
* @file
* Install, update, and uninstall functions for the Filter module.
+ *
+ * All sites require at least one text format (the fallback format) that all
+ * users have access to, so add it here. We initialize it as a simple, safe
+ * plain text format with very basic formatting, but it can be modified by
+ * installation profiles to have other properties.
+ *
+ * @see core/modules/filter/config/filter.format.plain_text.yml
*/
/**
* Implements hook_schema().
*/
function filter_schema() {
- $schema['filter'] = array(
- 'description' => 'Table that maps filters (HTML corrector) to text formats (Filtered HTML).',
- 'fields' => array(
- 'format' => array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'description' => 'Foreign key: The {filter_format}.format to which this filter is assigned.',
- ),
- 'module' => array(
- 'type' => 'varchar',
- 'length' => 64,
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'The origin module of the filter.',
- ),
- 'name' => array(
- 'type' => 'varchar',
- 'length' => 32,
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'Name of the filter being referenced.',
- ),
- 'weight' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => 'Weight of filter within format.',
- ),
- 'status' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => 'Filter enabled status. (1 = enabled, 0 = disabled)',
- ),
- 'settings' => array(
- 'type' => 'blob',
- 'not null' => FALSE,
- 'size' => 'big',
- 'serialize' => TRUE,
- 'description' => 'A serialized array of name value pairs that store the filter settings for the specific format.',
- ),
- ),
- 'primary key' => array('format', 'name'),
- 'indexes' => array(
- 'list' => array('weight', 'module', 'name'),
- ),
- );
- $schema['filter_format'] = array(
- 'description' => 'Stores text formats: custom groupings of filters, such as Filtered HTML.',
- 'fields' => array(
- 'format' => array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'description' => 'Primary Key: Unique machine name of the format.',
- ),
- 'name' => array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'Name of the text format (Filtered HTML).',
- 'translatable' => TRUE,
- ),
- 'cache' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'size' => 'tiny',
- 'description' => 'Flag to indicate whether format is cacheable. (1 = cacheable, 0 = not cacheable)',
- ),
- 'status' => array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 1,
- 'size' => 'tiny',
- 'description' => 'The status of the text format. (1 = enabled, 0 = disabled)',
- ),
- 'weight' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => 'Weight of text format to use when listing.',
- ),
- ),
- 'primary key' => array('format'),
- 'unique keys' => array(
- 'name' => array('name'),
- ),
- 'indexes' => array(
- 'status_weight' => array('status', 'weight'),
- ),
- );
-
$schema['cache_filter'] = drupal_get_schema_unprocessed('system', 'cache');
$schema['cache_filter']['description'] = 'Cache table for the Filter module to store already filtered pieces of text, identified by text format and hash of the text.';
@@ -112,40 +23,6 @@ function filter_schema() {
}
/**
- * Implements hook_install().
- */
-function filter_install() {
- // All sites require at least one text format (the fallback format) that all
- // users have access to, so add it here. We initialize it as a simple, safe
- // plain text format with very basic formatting, but it can be modified by
- // installation profiles to have other properties.
- $plain_text_format = array(
- 'format' => 'plain_text',
- 'name' => 'Plain text',
- 'weight' => 10,
- 'filters' => array(
- // Escape all HTML.
- 'filter_html_escape' => array(
- 'weight' => 0,
- 'status' => 1,
- ),
- // URL filter.
- 'filter_url' => array(
- 'weight' => 1,
- 'status' => 1,
- ),
- // Line break filter.
- 'filter_autop' => array(
- 'weight' => 2,
- 'status' => 1,
- ),
- ),
- );
- $plain_text_format = (object) $plain_text_format;
- filter_format_save($plain_text_format);
-}
-
-/**
* @addtogroup updates-7.x-to-8.x
* @{
*/
@@ -162,6 +39,39 @@ function filter_update_8000() {
}
/**
+ * Migrate filter formats into configuration.
+ *
+ * @ingroup config_upgrade
+ */
+function filter_update_8001() {
+ $result = db_query('SELECT * FROM {filter_format}');
+ foreach ($result as $filter_format) {
+ // Find the settings for this format.
+ $filters = array();
+ $settings = db_query('SELECT * FROM {filter} WHERE format = :format', array(':format' => $filter_format->format));
+ foreach($settings as $setting) {
+ $filters[$setting->name] = array(
+ 'weight' => $setting->weight,
+ 'settings' => unserialize($setting->settings),
+ 'status' => $setting->status,
+ );
+ }
+
+ // Save the config object.
+ $config = array(
+ 'format' => $filter_format->format,
+ 'name' => $filter_format->name,
+ 'roles' => array_values(user_roles(FALSE, 'use text format ' . $filter_format->format)),
+ 'status' => $filter_format->status,
+ 'weight' => $filter_format->weight,
+ 'filters' => $filters
+ );
+ $format = entity_create('filter_format', $config);
+ $format->save();
+ }
+}
+
+/**
* @} End of "defgroup updates-7.x-to-8.x".
* The next series of updates should start at 9000.
*/
diff --git a/core/modules/filter/filter.module b/core/modules/filter/filter.module
index 182bbb1..2f55b43 100644
--- a/core/modules/filter/filter.module
+++ b/core/modules/filter/filter.module
@@ -7,6 +7,7 @@
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Template\Attribute;
+use Drupal\filter\Plugin\Core\Entity\FilterFormat;
/**
* Non-HTML markup language filters that generate HTML.
@@ -170,6 +171,56 @@ function filter_menu() {
}
/**
+ * Implements MODULE_config_import_create().
+ */
+function filter_config_import_create($name, $new_config, $old_config) {
+ if (strpos($name, 'filter.format.') !== 0) {
+ return FALSE;
+ }
+
+ $filter_format = entity_create('filter_format', $new_config->get());
+ $filter_format->save();
+ return TRUE;
+}
+
+/**
+ * Implements MODULE_config_import_change().
+ */
+function filter_config_import_change($name, $new_config, $old_config) {
+ if (strpos($name, 'filter.format.') !== 0) {
+ return FALSE;
+ }
+
+ list(, , $id) = explode('.', $name);
+ $filter_format = entity_load('filter_format', $id);
+
+ $filter_format->original = clone $filter_format;
+ foreach ($old_config->get() as $property => $value) {
+ $filter_format->original->$property = $value;
+ }
+
+ foreach ($new_config->get() as $property => $value) {
+ $filter_format->$property = $value;
+ }
+
+ $filter_format->save();
+ return TRUE;
+}
+
+/**
+ * Implements MODULE_config_import_delete().
+ */
+function filter_config_import_delete($name, $new_config, $old_config) {
+ if (strpos($name, 'filter.format.') !== 0) {
+ return FALSE;
+ }
+
+ list(, , $id) = explode('.', $name);
+ entity_delete_multiple('filter_format', array($id));
+ return TRUE;
+}
+
+/**
* Access callback: Checks access for disabling text formats.
*
* @param $format
@@ -205,116 +256,6 @@ function filter_format_load($format_id) {
}
/**
- * Saves a text format object to the database.
- *
- * @param $format
- * A format object having the properties:
- * - format: A machine-readable name representing the ID of the text format
- * to save. If this corresponds to an existing text format, that format
- * will be updated; otherwise, a new format will be created.
- * - name: The title of the text format.
- * - status: (optional) An integer indicating whether the text format is
- * enabled (1) or not (0). Defaults to 1.
- * - weight: (optional) The weight of the text format, which controls its
- * placement in text format lists. If omitted, the weight is set to 0.
- * - filters: (optional) An associative, multi-dimensional array of filters
- * assigned to the text format, keyed by the name of each filter and using
- * the properties:
- * - weight: (optional) The weight of the filter in the text format. If
- * omitted, either the currently stored weight is retained (if there is
- * one), or the filter is assigned a weight of 10, which will usually
- * put it at the bottom of the list.
- * - status: (optional) A Boolean indicating whether the filter is
- * enabled in the text format. If omitted, the filter will be disabled.
- * - settings: (optional) An array of configured settings for the filter.
- * See hook_filter_info() for details.
- *
- * @return
- * SAVED_NEW or SAVED_UPDATED.
- */
-function filter_format_save($format) {
- $format->name = trim($format->name);
- $format->cache = _filter_format_is_cacheable($format);
- if (!isset($format->status)) {
- $format->status = 1;
- }
- if (!isset($format->weight)) {
- $format->weight = 0;
- }
-
- // Insert or update the text format.
- $return = db_merge('filter_format')
- ->key(array('format' => $format->format))
- ->fields(array(
- 'name' => $format->name,
- 'cache' => (int) $format->cache,
- 'status' => (int) $format->status,
- 'weight' => (int) $format->weight,
- ))
- ->execute();
-
- // Programmatic saves may not contain any filters.
- if (!isset($format->filters)) {
- $format->filters = array();
- }
- $filter_info = filter_get_filters();
- foreach ($filter_info as $name => $filter) {
- // If the format does not specify an explicit weight for a filter, assign
- // a default weight, either defined in hook_filter_info(), or the default of
- // 0 by filter_get_filters().
- if (!isset($format->filters[$name]['weight'])) {
- $format->filters[$name]['weight'] = $filter['weight'];
- }
- $format->filters[$name]['status'] = isset($format->filters[$name]['status']) ? $format->filters[$name]['status'] : 0;
- $format->filters[$name]['module'] = $filter['module'];
-
- // If settings were passed, only ensure default settings.
- if (isset($format->filters[$name]['settings'])) {
- if (isset($filter['default settings'])) {
- $format->filters[$name]['settings'] = array_merge($filter['default settings'], $format->filters[$name]['settings']);
- }
- }
- // Otherwise, use default settings or fall back to an empty array.
- else {
- $format->filters[$name]['settings'] = isset($filter['default settings']) ? $filter['default settings'] : array();
- }
-
- $fields = array();
- $fields['weight'] = $format->filters[$name]['weight'];
- $fields['status'] = $format->filters[$name]['status'];
- $fields['module'] = $format->filters[$name]['module'];
- $fields['settings'] = serialize($format->filters[$name]['settings']);
-
- db_merge('filter')
- ->key(array(
- 'format' => $format->format,
- 'name' => $name,
- ))
- ->fields($fields)
- ->execute();
- }
-
- if ($return == SAVED_NEW) {
- module_invoke_all('filter_format_insert', $format);
- }
- else {
- module_invoke_all('filter_format_update', $format);
- // Explicitly indicate that the format was updated. We need to do this
- // since if the filters were updated but the format object itself was not,
- // the merge query above would not return an indication that anything had
- // changed.
- $return = SAVED_UPDATED;
-
- // Clear the filter cache whenever a text format is updated.
- cache('filter')->deleteTags(array('filter_format' => $format->format));
- }
-
- filter_formats_reset();
-
- return $return;
-}
-
-/**
* Disables a text format.
*
* There is no core facility to re-enable a disabled format. It is not deleted
@@ -326,10 +267,8 @@ function filter_format_save($format) {
* The text format object to be disabled.
*/
function filter_format_disable($format) {
- db_update('filter_format')
- ->fields(array('status' => 0))
- ->condition('format', $format->format)
- ->execute();
+ $format->status = 0;
+ $format->save();
// Allow modules to react on text format deletion.
module_invoke_all('filter_format_disable', $format);
@@ -353,7 +292,8 @@ function filter_format_disable($format) {
* @see filter_format_load()
*/
function filter_format_exists($format_id) {
- return (bool) db_query_range('SELECT 1 FROM {filter_format} WHERE format = :format', 0, 1, array(':format' => $format_id))->fetchField();
+ $formats = entity_load_multiple('filter_format');
+ return !empty($formats[$format_id]);
}
/**
@@ -459,13 +399,14 @@ function filter_formats($account = NULL) {
$formats['all'] = $cache->data;
}
else {
- $formats['all'] = db_select('filter_format', 'ff')
- ->addTag('translatable')
- ->fields('ff')
- ->condition('status', 1)
- ->orderBy('weight')
- ->execute()
- ->fetchAllAssoc('format');
+ $filter_formats = entity_load_multiple('filter_format');
+ $formats['all'] = array();
+ foreach ($filter_formats as $format_name => $filter_format) {
+ if (!empty($filter_format->status)) {
+ $formats['all'][$format_name] = $filter_format;
+ }
+ }
+ @uasort($formats['all'], 'Drupal\Core\Config\Entity\ConfigEntityBase::sort');
cache()->set("filter_formats:{$language_interface->langcode}", $formats['all'], CacheBackendInterface::CACHE_PERMANENT, array('filter_formats' => TRUE));
}
@@ -588,19 +529,11 @@ function filter_get_filter_types_by_format($format_id) {
$filter_types = array();
$filters = filter_list_format($format_id);
-
- // Ignore filters that are disabled.
- $filters = array_filter($filters, function($filter) {
- return $filter->status;
- });
-
- $filters_info = filter_get_filters();
- foreach ($filters as $filter) {
- if (!isset($filters_info[$filter->name]['type'])) {
- throw new Exception(t('Filter %filter has no type specified.', array ('%filter' => $filter->name)));
+ foreach ($filters as $filter_id => $filter) {
+ // Ignore filters that are disabled.
+ if ($filter->status) {
+ $filter_types[] = $filter->type;
}
-
- $filter_types[] = $filters_info[$filter->name]['type'];
}
return array_unique($filter_types);
@@ -666,37 +599,29 @@ function filter_get_filters() {
$filters = &drupal_static(__FUNCTION__, array());
if (empty($filters)) {
- foreach (module_implements('filter_info') as $module) {
- $info = module_invoke($module, 'filter_info');
- if (isset($info) && is_array($info)) {
- // Assign the name of the module implementing the filters and ensure
- // default values.
- foreach (array_keys($info) as $name) {
- $info[$name]['module'] = $module;
- $info[$name] += array(
- 'description' => '',
- 'weight' => 0,
- );
- }
- $filters = array_merge($filters, $info);
- }
- }
- // Allow modules to alter filter definitions.
- drupal_alter('filter_info', $filters);
-
- uasort($filters, '_filter_list_cmp');
+ $filters = drupal_container()->get('plugin.manager.filter')->getDefinitions();
}
return $filters;
}
/**
- * Sorts an array of filters by filter name.
+ * Sorts an array of filters by filter status, weight, module, name.
*
- * Callback for uasort() within filter_get_filters().
+ * @see filter_list_format()
+ * @see Drupal\filter\Plugin\Core\Entity\FilterFormat::save()
*/
-function _filter_list_cmp($a, $b) {
- return strcmp($a['title'], $b['title']);
+function _filter_format_filter_cmp($a, $b) {
+ if ($a['status'] != $b['status']) {
+ return !empty($a['status']) ? -1 : 1;
+ }
+ if ($a['weight'] != $b['weight']) {
+ return ($a['weight'] < $b['weight']) ? -1 : 1;
+ }
+ elseif ($a['module'] != $b['module']) {
+ return strcmp($a['module'], $b['module']);
+ }
+ return strcmp($a['name'], $b['name']);
}
/**
@@ -730,16 +655,14 @@ function filter_format_allowcache($format_id) {
* TRUE if all the filters enabled in the given text format allow caching,
* FALSE otherwise.
*
- * @see filter_format_save()
+ * @see Drupal\filter\Plugin\Core\Entity\FilterFormat::save()
*/
function _filter_format_is_cacheable($format) {
if (empty($format->filters)) {
return TRUE;
}
- $filter_info = filter_get_filters();
- foreach ($format->filters as $name => $filter) {
- // By default, 'cache' is TRUE for all filters unless specified otherwise.
- if (!empty($filter['status']) && isset($filter_info[$name]['cache']) && !$filter_info[$name]['cache']) {
+ foreach ($format->filterPlugins as $name => $filter) {
+ if ($filter->status && !$filter->cache) {
return FALSE;
}
}
@@ -763,38 +686,25 @@ function _filter_format_is_cacheable($format) {
*/
function filter_list_format($format_id) {
$filters = &drupal_static(__FUNCTION__, array());
- $filter_info = filter_get_filters();
if (!isset($filters['all'])) {
if ($cache = cache()->get('filter_list_format')) {
$filters['all'] = $cache->data;
}
else {
- $result = db_query('SELECT * FROM {filter} ORDER BY weight, module, name');
- foreach ($result as $record) {
- $filters['all'][$record->format][$record->name] = $record;
+ $filter_formats = filter_formats();
+ foreach ($filter_formats as $filter_format) {
+ foreach ($filter_format->filterPlugins as $filter_name => $filter) {
+ $filters['all'][$filter_format->format][$filter_name] = $filter_format->filterPlugins[$filter_name];
+ }
+ @uasort($filters['all'][$filter_format->format], array('Drupal\filter\Plugin\filter\filter\FilterBase', 'sort'));
}
cache()->set('filter_list_format', $filters['all']);
}
}
- if (!isset($filters[$format_id])) {
- $format_filters = array();
- $filter_map = isset($filters['all'][$format_id]) ? $filters['all'][$format_id] : array();
- foreach ($filter_map as $name => $filter) {
- if (isset($filter_info[$name])) {
- $filter->title = $filter_info[$name]['title'];
- // Unpack stored filter settings.
- $filter->settings = (isset($filter->settings) ? unserialize($filter->settings) : array());
- // Merge in default settings.
- if (isset($filter_info[$name]['default settings'])) {
- $filter->settings += $filter_info[$name]['default settings'];
- }
-
- $format_filters[$name] = $filter;
- }
- }
- $filters[$format_id] = $format_filters;
+ if (!isset($filters[$format_id]) && isset($filters['all'][$format_id])) {
+ $filters[$format_id] = $filters['all'][$format_id];
}
return isset($filters[$format_id]) ? $filters[$format_id] : array();
@@ -870,36 +780,33 @@ function check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE,
// Get a complete list of filters, ordered properly.
$filters = filter_list_format($format->format);
- $filter_info = filter_get_filters();
// Give filters the chance to escape HTML-like data such as code or formulas.
foreach ($filters as $name => $filter) {
// If necessary, skip filters of a certain type.
- if (in_array($filter_info[$name]['type'], $filter_types_to_skip)) {
+ if (in_array($filter->type, $filter_types_to_skip)) {
continue;
}
- if ($filter->status && isset($filter_info[$name]['prepare callback'])) {
- $function = $filter_info[$name]['prepare callback'];
- $text = $function($text, $filter, $format, $langcode, $cache, $cache_id);
+ if ($filter->status) {
+ $text = $filter->prepare($text, $filter, $format, $langcode, $cache, $cache_id);
}
}
// Perform filtering.
foreach ($filters as $name => $filter) {
// If necessary, skip filters of a certain type.
- if (in_array($filter_info[$name]['type'], $filter_types_to_skip)) {
+ if (in_array($filter->type, $filter_types_to_skip)) {
continue;
}
- if ($filter->status && isset($filter_info[$name]['process callback'])) {
- $function = $filter_info[$name]['process callback'];
- $text = $function($text, $filter, $format, $langcode, $cache, $cache_id);
+ if ($filter->status) {
+ $text = $filter->process($text, $filter, $format, $langcode, $cache, $cache_id);
}
}
// Cache the filtered text. This cache is infinitely valid. It becomes
// obsolete when $text changes (which leads to a new $cache_id). It is
// automatically flushed when the text format is updated.
- // @see filter_format_save()
+ // @see Drupal\filter\Plugin\Core\Entity\FilterFormat::save()
if ($cache) {
cache('filter')->set($cache_id, $text, CacheBackendInterface::CACHE_PERMANENT, array('filter_format' => $format->format));
}
@@ -1151,7 +1058,6 @@ function _filter_tips($format_id, $long = FALSE) {
global $user;
$formats = filter_formats($user);
- $filter_info = filter_get_filters();
$tips = array();
@@ -1162,10 +1068,9 @@ function _filter_tips($format_id, $long = FALSE) {
foreach ($formats as $format) {
$filters = filter_list_format($format->format);
- $tips[$format->name] = array();
foreach ($filters as $name => $filter) {
- if ($filter->status && isset($filter_info[$name]['tips callback'])) {
- $tip = $filter_info[$name]['tips callback']($filter, $format, $long);
+ if ($filter->status) {
+ $tip = $filter->tips($filter, $format, $long);
if (isset($tip)) {
$tips[$format->name][$name] = array('tip' => $tip, 'id' => $name);
}
@@ -1309,93 +1214,6 @@ function theme_filter_guidelines($variables) {
*/
/**
- * Implements hook_filter_info().
- */
-function filter_filter_info() {
- $filters['filter_html'] = array(
- 'title' => t('Limit allowed HTML tags'),
- 'type' => FILTER_TYPE_HTML_RESTRICTOR,
- 'process callback' => '_filter_html',
- 'settings callback' => '_filter_html_settings',
- 'default settings' => array(
- 'allowed_html' => ' -
-
-
',
- 'filter_html_help' => 1,
- 'filter_html_nofollow' => 0,
- ),
- 'tips callback' => '_filter_html_tips',
- 'weight' => -10,
- );
- $filters['filter_autop'] = array(
- 'title' => t('Convert line breaks into HTML (i.e. <br>
and <p>
)'),
- 'type' => FILTER_TYPE_MARKUP_LANGUAGE,
- 'process callback' => '_filter_autop',
- 'tips callback' => '_filter_autop_tips',
- );
- $filters['filter_url'] = array(
- 'title' => t('Convert URLs into links'),
- 'type' => FILTER_TYPE_MARKUP_LANGUAGE,
- 'process callback' => '_filter_url',
- 'settings callback' => '_filter_url_settings',
- 'default settings' => array(
- 'filter_url_length' => 72,
- ),
- 'tips callback' => '_filter_url_tips',
- );
- $filters['filter_html_image_secure'] = array(
- 'title' => t('Restrict images to this site'),
- 'type' => FILTER_TYPE_HTML_RESTRICTOR,
- 'description' => t('Disallows usage of <img> tag sources that are not hosted on this site by replacing them with a placeholder image.'),
- 'process callback' => '_filter_html_image_secure_process',
- 'tips callback' => '_filter_html_image_secure_tips',
- // Supposed to run after other filters and before HTML corrector by default.
- 'weight' => 9,
- );
- $filters['filter_htmlcorrector'] = array(
- 'title' => t('Correct faulty and chopped off HTML'),
- 'type' => FILTER_TYPE_HTML_RESTRICTOR,
- 'process callback' => '_filter_htmlcorrector',
- 'weight' => 10,
- );
- $filters['filter_html_escape'] = array(
- 'title' => t('Display any HTML as plain text'),
- 'type' => FILTER_TYPE_HTML_RESTRICTOR,
- 'process callback' => '_filter_html_escape',
- 'tips callback' => '_filter_html_escape_tips',
- 'weight' => -10,
- );
- return $filters;
-}
-
-/**
- * Filter settings callback for the HTML content filter.
- *
- * See hook_filter_FILTER_settings() for documentation of parameters and return
- * value.
- */
-function _filter_html_settings($form, &$form_state, $filter, $format, $defaults) {
- $filter->settings += $defaults;
-
- $settings['allowed_html'] = array(
- '#type' => 'textfield',
- '#title' => t('Allowed HTML tags'),
- '#default_value' => $filter->settings['allowed_html'],
- '#maxlength' => 1024,
- '#description' => t('A list of HTML tags that can be used. JavaScript event attributes, JavaScript URLs, and CSS are always stripped.'),
- );
- $settings['filter_html_help'] = array(
- '#type' => 'checkbox',
- '#title' => t('Display basic HTML help in long filter tips'),
- '#default_value' => $filter->settings['filter_html_help'],
- );
- $settings['filter_html_nofollow'] = array(
- '#type' => 'checkbox',
- '#title' => t('Add rel="nofollow" to all links'),
- '#default_value' => $filter->settings['filter_html_nofollow'],
- );
- return $settings;
-}
-
-/**
* Provides filtering of input into accepted HTML.
*/
function _filter_html($text, $filter) {
@@ -1415,125 +1233,6 @@ function _filter_html($text, $filter) {
}
/**
- * Filter tips callback: Provides help for the HTML filter.
- *
- * @see filter_filter_info()
- */
-function _filter_html_tips($filter, $format, $long = FALSE) {
- global $base_url;
-
- if (!($allowed_html = $filter->settings['allowed_html'])) {
- return;
- }
- $output = t('Allowed HTML tags: @tags', array('@tags' => $allowed_html));
- if (!$long) {
- return $output;
- }
-
- $output = '
' . $output . '
';
- if (!$filter->settings['filter_html_help']) {
- return $output;
- }
-
- $output .= '' . t('This site allows HTML content. While learning all of HTML may feel intimidating, learning how to use a very small number of the most basic HTML "tags" is very easy. This table provides examples for each tag that is enabled on this site.') . '
';
- $output .= '' . t('For more information see W3C\'s HTML Specifications or use your favorite search engine to find other sites that explain HTML.', array('@html-specifications' => 'http://www.w3.org/TR/html/')) . '
';
- $tips = array(
- 'a' => array(t('Anchors are used to make links to other pages.'), '' . check_plain(config('system.site')->get('name')) . ''),
- 'br' => array(t('By default line break tags are automatically added, so use this tag to add additional ones. Use of this tag is different because it is not used with an open/close pair like all the others. Use the extra " /" inside the tag to maintain XHTML 1.0 compatibility'), t('Text with
line break')),
- 'p' => array(t('By default paragraph tags are automatically added, so use this tag to add additional ones.'), '' . t('Paragraph one.') . '
' . t('Paragraph two.') . '
'),
- 'strong' => array(t('Strong', array(), array('context' => 'Font weight')), '' . t('Strong', array(), array('context' => 'Font weight')) . ''),
- 'em' => array(t('Emphasized'), '' . t('Emphasized') . ''),
- 'cite' => array(t('Cited'), '' . t('Cited') . ''),
- 'code' => array(t('Coded text used to show programming source code'), '' . t('Coded') . '
'),
- 'b' => array(t('Bolded'), '' . t('Bolded') . ''),
- 'u' => array(t('Underlined'), '' . t('Underlined') . ''),
- 'i' => array(t('Italicized'), '' . t('Italicized') . ''),
- 'sup' => array(t('Superscripted'), t('Superscripted')),
- 'sub' => array(t('Subscripted'), t('Subscripted')),
- 'pre' => array(t('Preformatted'), '' . t('Preformatted') . '
'),
- 'abbr' => array(t('Abbreviation'), t('Abbrev.')),
- 'acronym' => array(t('Acronym'), t('TLA')),
- 'blockquote' => array(t('Block quoted'), '' . t('Block quoted') . '
'),
- 'q' => array(t('Quoted inline'), '' . t('Quoted inline') . '
'),
- // Assumes and describes tr, td, th.
- 'table' => array(t('Table'), ' ' . t('Table header') . ' ' . t('Table cell') . '
'),
- 'tr' => NULL, 'td' => NULL, 'th' => NULL,
- 'del' => array(t('Deleted'), '' . t('Deleted') . ''),
- 'ins' => array(t('Inserted'), '' . t('Inserted') . ''),
- // Assumes and describes li.
- 'ol' => array(t('Ordered list - use the <li> to begin each list item'), ' - ' . t('First item') . '
- ' . t('Second item') . '
'),
- 'ul' => array(t('Unordered list - use the <li> to begin each list item'), ' - ' . t('First item') . '
- ' . t('Second item') . '
'),
- 'li' => NULL,
- // Assumes and describes dt and dd.
- 'dl' => array(t('Definition lists are similar to other HTML lists. <dl> begins the definition list, <dt> begins the definition term and <dd> begins the definition description.'), ' - ' . t('First term') . '
- ' . t('First definition') . '
- ' . t('Second term') . '
- ' . t('Second definition') . '
'),
- 'dt' => NULL, 'dd' => NULL,
- 'h1' => array(t('Heading'), '' . t('Title') . '
'),
- 'h2' => array(t('Heading'), '' . t('Subtitle') . '
'),
- 'h3' => array(t('Heading'), '' . t('Subtitle three') . '
'),
- 'h4' => array(t('Heading'), '' . t('Subtitle four') . '
'),
- 'h5' => array(t('Heading'), '' . t('Subtitle five') . '
'),
- 'h6' => array(t('Heading'), '' . t('Subtitle six') . '
')
- );
- $header = array(t('Tag Description'), t('You Type'), t('You Get'));
- preg_match_all('/<([a-z0-9]+)[^a-z0-9]/i', $allowed_html, $out);
- foreach ($out[1] as $tag) {
- if (!empty($tips[$tag])) {
- $rows[] = array(
- array('data' => $tips[$tag][0], 'class' => array('description')),
- array('data' => '' . check_plain($tips[$tag][1]) . '
', 'class' => array('type')),
- array('data' => $tips[$tag][1], 'class' => array('get'))
- );
- }
- else {
- $rows[] = array(
- array('data' => t('No help provided for tag %tag.', array('%tag' => $tag)), 'class' => array('description'), 'colspan' => 3),
- );
- }
- }
- $output .= theme('table', array('header' => $header, 'rows' => $rows));
-
- $output .= '' . t('Most unusual characters can be directly entered without any problems.') . '
';
- $output .= '' . t('If you do encounter problems, try using HTML character entities. A common example looks like & for an ampersand & character. For a full list of entities see HTML\'s entities page. Some of the available characters include:', array('@html-entities' => 'http://www.w3.org/TR/html4/sgml/entities.html')) . '
';
-
- $entities = array(
- array(t('Ampersand'), '&'),
- array(t('Greater than'), '>'),
- array(t('Less than'), '<'),
- array(t('Quotation mark'), '"'),
- );
- $header = array(t('Character Description'), t('You Type'), t('You Get'));
- unset($rows);
- foreach ($entities as $entity) {
- $rows[] = array(
- array('data' => $entity[0], 'class' => array('description')),
- array('data' => '' . check_plain($entity[1]) . '
', 'class' => array('type')),
- array('data' => $entity[1], 'class' => array('get'))
- );
- }
- $output .= theme('table', array('header' => $header, 'rows' => $rows));
- return $output;
-}
-
-/**
- * Filter URL settings callback: Provides settings for the URL filter.
- *
- * @see filter_filter_info()
- */
-function _filter_url_settings($form, &$form_state, $filter, $format, $defaults) {
- $filter->settings += $defaults;
-
- $settings['filter_url_length'] = array(
- '#type' => 'number',
- '#title' => t('Maximum link text length'),
- '#default_value' => $filter->settings['filter_url_length'],
- '#min' => 1,
- '#field_suffix' => t('characters'),
- '#description' => t('URLs longer than this number of characters will be truncated to prevent long strings that break formatting. The link itself will be retained; just the text portion of the link will be truncated.'),
- );
- return $settings;
-}
-
-/**
* Converts text into hyperlinks automatically.
*
* This filter identifies and makes clickable three types of "links".
@@ -1760,15 +1459,6 @@ function _filter_url_trim($text, $length = NULL) {
}
/**
- * Filter tips callback: Provides help for the URL filter.
- *
- * @see filter_filter_info()
- */
-function _filter_url_tips($filter, $format, $long = FALSE) {
- return t('Web page addresses and e-mail addresses turn into links automatically.');
-}
-
-/**
* Scans the input and makes sure that HTML tags are properly closed.
*/
function _filter_htmlcorrector($text) {
@@ -1843,20 +1533,6 @@ function _filter_autop($text) {
}
/**
- * Filter tips callback: Provides help for the auto-paragraph filter.
- *
- * @see filter_filter_info()
- */
-function _filter_autop_tips($filter, $format, $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.');
- }
- else {
- return t('Lines and paragraphs break automatically.');
- }
-}
-
-/**
* Escapes all HTML tags, so they will be visible instead of being effective.
*/
function _filter_html_escape($text) {
@@ -1864,15 +1540,6 @@ function _filter_html_escape($text) {
}
/**
- * Filter tips callback: Provides help for the HTML escaping filter.
- *
- * @see filter_filter_info()
- */
-function _filter_html_escape_tips($filter, $format, $long = FALSE) {
- return t('No HTML tags allowed.');
-}
-
-/**
* Process callback for local image filter.
*/
function _filter_html_image_secure_process($text) {
@@ -1938,13 +1605,6 @@ function theme_filter_html_image_secure_image(&$variables) {
}
/**
- * Filter tips callback for secure HTML image filter.
- */
-function _filter_html_image_secure_tips($filter, $format, $long = FALSE) {
- return t('Only images hosted on this site may be used in <img> tags.');
-}
-
-/**
* @} End of "defgroup standard_filters".
*/
diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterAPITest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterAPITest.php
index e355f2d..754cd1c 100644
--- a/core/modules/filter/lib/Drupal/filter/Tests/FilterAPITest.php
+++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterAPITest.php
@@ -26,7 +26,7 @@ function setUp() {
parent::setUp();
// Create Filtered HTML format.
- $filtered_html_format = array(
+ $filtered_html_format_config = array(
'format' => 'filtered_html',
'name' => 'Filtered HTML',
'filters' => array(
@@ -41,11 +41,11 @@ function setUp() {
),
)
);
- $filtered_html_format = (object) $filtered_html_format;
- filter_format_save($filtered_html_format);
+ $filtered_html_format = entity_create('filter_format', $filtered_html_format_config);
+ $filtered_html_format->save();
// Create Full HTML format.
- $full_html_format = array(
+ $full_html_format_config = array(
'format' => 'full_html',
'name' => 'Full HTML',
'weight' => 1,
@@ -56,8 +56,8 @@ function setUp() {
),
),
);
- $full_html_format = (object) $full_html_format;
- filter_format_save($full_html_format);
+ $full_html_format = entity_create('filter_format', $full_html_format_config);
+ $full_html_format->save();
}
/**
diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterAdminTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterAdminTest.php
index c2b76d2..e7b1330 100644
--- a/core/modules/filter/lib/Drupal/filter/Tests/FilterAdminTest.php
+++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterAdminTest.php
@@ -164,14 +164,13 @@ function testFilterAdmin() {
));
$this->assertTrue(!empty($elements), 'Reorder confirmed in admin interface.');
- $result = db_query('SELECT * FROM {filter} WHERE format = :format ORDER BY weight ASC', array(':format' => $filtered));
- $filters = array();
- foreach ($result as $filter) {
- if ($filter->name == $second_filter || $filter->name == $first_filter) {
- $filters[] = $filter;
+ $filter_format = entity_load('filter_format', $filtered);
+ foreach ($filter_format->filters as $filter_name => $filter) {
+ if ($filter_name == $second_filter || $filter_name == $first_filter) {
+ $filters[] = $filter_name;
}
}
- $this->assertTrue(($filters[0]->name == $second_filter && $filters[1]->name == $first_filter), 'Order confirmed in database.');
+ $this->assertTrue(($filters[0] == $second_filter && $filters[1] == $first_filter), t('Order confirmed in database.'));
// Add format.
$edit = array();
diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterCrudTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterCrudTest.php
index 7b4c6f5..672a283 100644
--- a/core/modules/filter/lib/Drupal/filter/Tests/FilterCrudTest.php
+++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterCrudTest.php
@@ -35,15 +35,15 @@ public static function getInfo() {
*/
function testTextFormatCrud() {
// Add a text format with minimum data only.
- $format = new stdClass();
+ $format = entity_create('filter_format', array());
$format->format = 'empty_format';
$format->name = 'Empty format';
- filter_format_save($format);
+ $format->save();
$this->verifyTextFormat($format);
$this->verifyFilters($format);
// Add another text format specifying all possible properties.
- $format = new stdClass();
+ $format = entity_create('filter_format', array());
$format->format = 'custom_format';
$format->name = 'Custom format';
$format->filters = array(
@@ -54,7 +54,7 @@ function testTextFormatCrud() {
),
),
);
- filter_format_save($format);
+ $format->save();
$this->verifyTextFormat($format);
$this->verifyFilters($format);
@@ -62,21 +62,19 @@ function testTextFormatCrud() {
$format->name = 'Altered format';
$format->filters['filter_url']['status'] = 0;
$format->filters['filter_autop']['status'] = 1;
- filter_format_save($format);
+ $format->save();
$this->verifyTextFormat($format);
$this->verifyFilters($format);
// Add a uncacheable filter and save again.
$format->filters['filter_test_uncacheable']['status'] = 1;
- filter_format_save($format);
+ $format->save();
$this->verifyTextFormat($format);
$this->verifyFilters($format);
// Disable the text format.
filter_format_disable($format);
- $db_format = db_query("SELECT * FROM {filter_format} WHERE format = :format", array(':format' => $format->format))->fetchObject();
- $this->assertFalse($db_format->status, 'Database: Disabled text format is marked as disabled.');
$formats = filter_formats();
$this->assertTrue(!isset($formats[$format->format]), 'filter_formats: Disabled text format no longer exists.');
}
@@ -86,16 +84,6 @@ function testTextFormatCrud() {
*/
function verifyTextFormat($format) {
$t_args = array('%format' => $format->name);
- // Verify text format database record.
- $db_format = db_select('filter_format', 'ff')
- ->fields('ff')
- ->condition('format', $format->format)
- ->execute()
- ->fetchObject();
- $this->assertEqual($db_format->format, $format->format, format_string('Database: Proper format id for text format %format.', $t_args));
- $this->assertEqual($db_format->name, $format->name, format_string('Database: Proper title for text format %format.', $t_args));
- $this->assertEqual($db_format->cache, $format->cache, format_string('Database: Proper cache indicator for text format %format.', $t_args));
- $this->assertEqual($db_format->weight, $format->weight, format_string('Database: Proper weight for text format %format.', $t_args));
// Verify filter_format_load().
$filter_format = filter_format_load($format->format);
@@ -105,13 +93,12 @@ function verifyTextFormat($format) {
$this->assertEqual($filter_format->weight, $format->weight, format_string('filter_format_load: Proper weight for text format %format.', $t_args));
// Verify the 'cache' text format property according to enabled filters.
- $filter_info = filter_get_filters();
$filters = filter_list_format($filter_format->format);
$cacheable = TRUE;
foreach ($filters as $name => $filter) {
// If this filter is not cacheable, update $cacheable accordingly, so we
// can verify $format->cache after iterating over all filters.
- if ($filter->status && isset($filter_info[$name]['cache']) && !$filter_info[$name]['cache']) {
+ if ($filter->status && !$filter->cache) {
$cacheable = FALSE;
break;
}
@@ -123,27 +110,7 @@ function verifyTextFormat($format) {
* Verifies that filters are properly stored for a text format.
*/
function verifyFilters($format) {
- // Verify filter database records.
- $filters = db_query("SELECT * FROM {filter} WHERE format = :format", array(':format' => $format->format))->fetchAllAssoc('name');
$format_filters = $format->filters;
- foreach ($filters as $name => $filter) {
- $t_args = array('%format' => $format->name, '%filter' => $name);
-
- // Verify that filter status is properly stored.
- $this->assertEqual($filter->status, $format_filters[$name]['status'], format_string('Database: Proper status for %filter in text format %format.', $t_args));
-
- // Verify that filter settings were properly stored.
- $this->assertEqual(unserialize($filter->settings), isset($format_filters[$name]['settings']) ? $format_filters[$name]['settings'] : array(), format_string('Database: Proper filter settings for %filter in text format %format.', $t_args));
-
- // Verify that each filter has a module name assigned.
- $this->assertTrue(!empty($filter->module), format_string('Database: Proper module name for %filter in text format %format.', $t_args));
-
- // Remove the filter from the copy of saved $format to check whether all
- // filters have been processed later.
- unset($format_filters[$name]);
- }
- // Verify that all filters have been processed.
- $this->assertTrue(empty($format_filters), 'Database contains values for all filters in the saved format.');
// Verify filter_list_format().
$filters = filter_list_format($format->format);
diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterDefaultFormatTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterDefaultFormatTest.php
index 103d777..718e8d8 100644
--- a/core/modules/filter/lib/Drupal/filter/Tests/FilterDefaultFormatTest.php
+++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterDefaultFormatTest.php
@@ -45,7 +45,17 @@ function testDefaultTextFormats() {
// Adjust the weights so that the first and second formats (in that order)
// are the two lowest weighted formats available to any user.
- $minimum_weight = db_query("SELECT MIN(weight) FROM {filter_format}")->fetchField();
+ $minimum_weight = NULL;
+ foreach (entity_load_multiple('filter_format') as $format) {
+ if (is_null($minimum_weight)) {
+ $minimum_weight = $format->weight;
+ }
+ else {
+ if ($minimum_weight > $format->weight) {
+ $minimum_weight = $format->weight;
+ }
+ }
+ }
$edit = array();
$edit['formats[' . $first_format->format . '][weight]'] = $minimum_weight - 2;
$edit['formats[' . $second_format->format . '][weight]'] = $minimum_weight - 1;
diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterHtmlImageSecureTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterHtmlImageSecureTest.php
index a7e38ac..4d664a8 100644
--- a/core/modules/filter/lib/Drupal/filter/Tests/FilterHtmlImageSecureTest.php
+++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterHtmlImageSecureTest.php
@@ -33,7 +33,7 @@ function setUp() {
parent::setUp();
// Setup Filtered HTML text format.
- $filtered_html_format = array(
+ $filtered_html_format_config = array(
'format' => 'filtered_html',
'name' => 'Filtered HTML',
'filters' => array(
@@ -51,8 +51,8 @@ function setUp() {
),
),
);
- $filtered_html_format = (object) $filtered_html_format;
- filter_format_save($filtered_html_format);
+ $filtered_html_format = entity_create('filter_format', $filtered_html_format_config);
+ $filtered_html_format->save();
// Setup users.
$this->checkPermissions(array(), TRUE);
diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterSecurityTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterSecurityTest.php
index 5928a4d..636ff51 100644
--- a/core/modules/filter/lib/Drupal/filter/Tests/FilterSecurityTest.php
+++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterSecurityTest.php
@@ -43,7 +43,7 @@ function setUp() {
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
// Create Filtered HTML format.
- $filtered_html_format = array(
+ $filtered_html_format_config = array(
'format' => 'filtered_html',
'name' => 'Filtered HTML',
'filters' => array(
@@ -53,8 +53,8 @@ function setUp() {
),
)
);
- $filtered_html_format = (object) $filtered_html_format;
- filter_format_save($filtered_html_format);
+ $filtered_html_format = entity_create('filter_format', $filtered_html_format_config);
+ $filtered_html_format->save();
$filtered_html_permission = filter_permission_name($filtered_html_format);
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array($filtered_html_permission));
diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterSettingsTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterSettingsTest.php
index 6d2ab99..be003ee 100644
--- a/core/modules/filter/lib/Drupal/filter/Tests/FilterSettingsTest.php
+++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterSettingsTest.php
@@ -32,16 +32,17 @@ public static function getInfo() {
* Tests explicit and implicit default settings for filters.
*/
function testFilterDefaults() {
- $filter_info = filter_filter_info();
+ $filter_info = filter_get_filters();
$filters = array_fill_keys(array_keys($filter_info), array());
// Create text format using filter default settings.
- $filter_defaults_format = (object) array(
+ $filter_defaults_format_config = array(
'format' => 'filter_defaults',
'name' => 'Filter defaults',
'filters' => $filters,
);
- filter_format_save($filter_defaults_format);
+ $filter_defaults_format = entity_create('filter_format', $filter_defaults_format_config);
+ $filter_defaults_format->save();
// Verify that default weights defined in hook_filter_info() were applied.
$saved_settings = array();
@@ -56,7 +57,7 @@ function testFilterDefaults() {
}
// Re-save the text format.
- filter_format_save($filter_defaults_format);
+ $filter_defaults_format->save();
// Reload it from scratch.
filter_formats_reset();
$filter_defaults_format = filter_format_load($filter_defaults_format->format);
diff --git a/core/modules/php/php.install b/core/modules/php/php.install
index 12944dd..f2281f2 100644
--- a/core/modules/php/php.install
+++ b/core/modules/php/php.install
@@ -9,13 +9,20 @@
* Implements hook_enable().
*/
function php_enable() {
- $format_exists = (bool) db_query_range('SELECT 1 FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'PHP code'))->fetchField();
// Add a PHP code text format, if it does not exist. Do this only for the
// first install (or if the format has been manually deleted) as there is no
// reliable method to identify the format in an uninstall hook or in
// subsequent clean installs.
+ $format_exists = FALSE;
+ $filter_formats = entity_load_multiple('filter_format');
+ foreach ($filter_formats as $format) {
+ if ($format->name == 'PHP code') {
+ $format_exists = TRUE;
+ break;
+ }
+ }
if (!$format_exists) {
- $php_format = array(
+ $php_format_config = array(
'format' => 'php_code',
'name' => 'PHP code',
// 'Plain text' format is installed with a weight of 10 by default. Use a
@@ -30,8 +37,8 @@ function php_enable() {
),
),
);
- $php_format = (object) $php_format;
- filter_format_save($php_format);
+ $php_format = entity_create('filter_format', $php_format_config);
+ $php_format->save();
drupal_set_message(t('A PHP code text format has been created.', array('@php-code' => url('admin/config/content/formats/' . $php_format->format))));
}
diff --git a/core/modules/php/php.module b/core/modules/php/php.module
index 8e885e4..2932bfa 100644
--- a/core/modules/php/php.module
+++ b/core/modules/php/php.module
@@ -86,63 +86,3 @@ function php_eval($code) {
return $output;
}
-
-/**
- * Implements hook_filter_FILTER_tips().
- *
- * @see php_filter_info()
- */
-function _php_filter_tips($filter, $format, $long = FALSE) {
- global $base_url;
- if ($long) {
- $output = '' . t('Using custom PHP code') . '
';
- $output .= '' . t('Custom PHP code may be embedded in some types of site content, including posts and blocks. While embedding PHP code inside a post or block is a powerful and flexible feature when used by a trusted user with PHP experience, it is a significant and dangerous security risk when used improperly. Even a small mistake when posting PHP code may accidentally compromise your site.') . '
';
- $output .= '' . t('If you are unfamiliar with PHP, SQL, or Drupal, avoid using custom PHP code within posts. Experimenting with PHP may corrupt your database, render your site inoperable, or significantly compromise security.') . '
';
- $output .= '' . t('Notes:') . '
';
- $output .= '- ' . t('Remember to double-check each line for syntax and logic errors before saving.') . '
';
- $output .= '- ' . t('Statements must be correctly terminated with semicolons.') . '
';
- $output .= '- ' . t('Global variables used within your PHP code retain their values after your script executes.') . '
';
- $output .= '- ' . t('
register_globals
is turned off. If you need to use forms, understand and use the functions in the Drupal Form API.', array('@formapi' => url('http://api.drupal.org/api/group/form_api/8'))) . ' ';
- $output .= '- ' . t('Use a
print
or return
statement in your code to output content.') . ' ';
- $output .= '- ' . t('Develop and test your PHP code using a separate test script and sample database before deploying on a production site.') . '
';
- $output .= '- ' . t('Consider including your custom PHP code within a site-specific module or
template.php
file rather than embedding it directly into a post or block.') . ' ';
- $output .= '- ' . t('Be aware that the ability to embed PHP code within content is provided by the PHP Filter module. If this module is disabled or deleted, then blocks and posts with embedded PHP may display, rather than execute, the PHP code.') . '
';
- $output .= '' . t('A basic example: Creating a "Welcome" block that greets visitors with a simple message.') . '
';
- $output .= '- ' . t('
Add a custom block to your site, named "Welcome" . With its text format set to "PHP code" (or another format supporting PHP input), add the following in the Block body:
-
-print t(\'Welcome visitor! Thank you for visiting.\');
-
') . ' ';
- $output .= '- ' . t('
To display the name of a registered user, use this instead:
-
-global $user;
-if ($user->uid) {
- print t(\'Welcome @name! Thank you for visiting.\', array(\'@name\' => user_format_name($user)));
-}
-else {
- print t(\'Welcome visitor! Thank you for visiting.\');
-}
-
') . '
';
- $output .= '' . t('Drupal.org offers some example PHP snippets, or you can create your own with some PHP experience and knowledge of the Drupal system.', array('@drupal' => url('http://drupal.org'), '@php-snippets' => url('http://drupal.org/documentation/customization/php-snippets'))) . '
';
- return $output;
- }
- else {
- return t('You may post PHP code. You should include <?php ?> tags.');
- }
-}
-
-/**
- * Implements hook_filter_info().
- *
- * Provide PHP code filter. Use with care.
- */
-function php_filter_info() {
- $filters['php_code'] = array(
- 'title' => t('PHP evaluator'),
- 'type' => FILTER_TYPE_MARKUP_LANGUAGE,
- 'description' => t('Executes a piece of PHP code. The usage of this filter should be restricted to administrators only!'),
- 'process callback' => 'php_eval',
- 'tips callback' => '_php_filter_tips',
- 'cache' => FALSE,
- );
- return $filters;
-}
diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchRankingTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchRankingTest.php
index a57e483..72c2431 100644
--- a/core/modules/search/lib/Drupal/search/Tests/SearchRankingTest.php
+++ b/core/modules/search/lib/Drupal/search/Tests/SearchRankingTest.php
@@ -106,12 +106,12 @@ function testRankings() {
* Test rankings of HTML tags.
*/
function testHTMLRankings() {
- $full_html_format = array(
+ $full_html_format_config = array(
'format' => 'full_html',
'name' => 'Full HTML',
);
- $full_html_format = (object) $full_html_format;
- filter_format_save($full_html_format);
+ $full_html_format = entity_create('filter_format', $full_html_format_config);
+ $full_html_format->save();
// Login with sufficient privileges.
$this->drupalLogin($this->drupalCreateUser(array('create page content')));
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php b/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php
index 5813ffd..bff7d70 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php
@@ -74,8 +74,7 @@ function testEnableModulesLoad() {
* Tests expected installation behavior of enableModules().
*/
function testEnableModulesInstall() {
- $module = 'filter';
- $table = 'filter';
+ $module = 'field';
// @todo Remove after configuration system conversion.
$this->enableModules(array('system'), FALSE);
@@ -88,10 +87,6 @@ function testEnableModulesInstall() {
$list = module_list('permission');
$this->assertFalse(in_array($module, $list), "{$module}_permission() in module_implements() not found.");
- $this->assertFalse(db_table_exists($table), "'$table' database table not found.");
- $schema = drupal_get_schema($table);
- $this->assertFalse($schema, "'$table' table schema not found.");
-
// Enable the module.
$this->enableModules(array($module));
@@ -101,10 +96,6 @@ function testEnableModulesInstall() {
$this->assertTrue(in_array($module, $list), "$module module in module_list() found.");
$list = module_list('permission');
$this->assertTrue(in_array($module, $list), "{$module}_permission() in module_implements() found.");
-
- $this->assertTrue(db_table_exists($table), "'$table' database table found.");
- $schema = drupal_get_schema($table);
- $this->assertTrue($schema, "'$table' table schema found.");
}
/**
diff --git a/core/modules/system/lib/Drupal/system/Tests/Form/FormTest.php b/core/modules/system/lib/Drupal/system/Tests/Form/FormTest.php
index 9efe0c3..e1e0315 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Form/FormTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Form/FormTest.php
@@ -29,12 +29,12 @@ public static function getInfo() {
function setUp() {
parent::setUp();
- $filtered_html_format = array(
+ $filtered_html_format_config = array(
'format' => 'filtered_html',
'name' => 'Filtered HTML',
);
- $filtered_html_format = (object) $filtered_html_format;
- filter_format_save($filtered_html_format);
+ $filtered_html_format = entity_create('filter_format', $filtered_html_format_config);
+ $filtered_html_format->save();
$filtered_html_permission = filter_permission_name($filtered_html_format);
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array($filtered_html_permission));
diff --git a/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php b/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php
index 9c51a89..2a9f980 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php
@@ -152,7 +152,8 @@ function testBreadCrumbs() {
$this->assertBreadcrumb("admin/structure/types/manage/$type/fields/body/widget-type", $trail);
// Verify Filter text format administration breadcrumbs.
- $format = db_query_range("SELECT format, name FROM {filter_format}", 1, 1)->fetch();
+ $filter_formats = filter_formats();
+ $format = reset($filter_formats);
$format_id = $format->format;
$trail = $config + array(
'admin/config/content' => t('Content authoring'),
diff --git a/core/modules/system/system.install b/core/modules/system/system.install
index ca5d6de..2e73a16 100644
--- a/core/modules/system/system.install
+++ b/core/modules/system/system.install
@@ -1377,6 +1377,26 @@ function system_schema() {
),
);
+ $schema['config_snapshot'] = array(
+ 'description' => 'Stores a snapshot of the last imported configuration.',
+ 'fields' => array(
+ 'name' => array(
+ 'description' => 'The identifier for the config object (the name of the file, minus the file extension).',
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'not null' => TRUE,
+ 'default' => '',
+ ),
+ 'data' => array(
+ 'description' => 'The raw data for this configuration object.',
+ 'type' => 'blob',
+ 'not null' => TRUE,
+ 'size' => 'big',
+ ),
+ ),
+ 'primary key' => array('name'),
+ );
+
return $schema;
}
diff --git a/core/modules/system/tests/modules/filter_test/filter_test.module b/core/modules/system/tests/modules/filter_test/filter_test.module
index a61941a..e3983b4 100644
--- a/core/modules/system/tests/modules/filter_test/filter_test.module
+++ b/core/modules/system/tests/modules/filter_test/filter_test.module
@@ -25,40 +25,3 @@ function filter_test_filter_format_update($format) {
function filter_test_filter_format_disable($format) {
drupal_set_message('hook_filter_format_disable invoked.');
}
-
-/**
- * Implements hook_filter_info().
- */
-function filter_test_filter_info() {
- $filters['filter_test_uncacheable'] = array(
- 'title' => 'Uncacheable filter',
- 'type' => FILTER_TYPE_TRANSFORM_IRREVERSIBLE,
- 'description' => 'Does nothing, but makes a text format uncacheable.',
- 'cache' => FALSE,
- );
- $filters['filter_test_replace'] = array(
- 'title' => 'Testing filter',
- 'type' => FILTER_TYPE_TRANSFORM_IRREVERSIBLE,
- 'description' => 'Replaces all content with filter and text format information.',
- 'process callback' => 'filter_test_replace',
- );
- return $filters;
-}
-
-/**
- * Process handler for filter_test_replace filter.
- *
- * Replaces all text with filter and text format information.
- */
-function filter_test_replace($text, $filter, $format, $langcode, $cache, $cache_id) {
- $text = array();
- $text[] = 'Filter: ' . $filter->title . ' (' . $filter->name . ')';
- $text[] = 'Format: ' . $format->name . ' (' . $format->format . ')';
- $text[] = 'Language: ' . $langcode;
- $text[] = 'Cache: ' . ($cache ? 'Enabled' : 'Disabled');
- if ($cache_id) {
- $text[] = 'Cache ID: ' . $cache_id;
- }
- return implode("
\n", $text);
-}
-
diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTestBase.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTestBase.php
index 0317ad6..fab42f0 100644
--- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTestBase.php
+++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTestBase.php
@@ -51,11 +51,13 @@ function createVocabulary() {
* Returns a new term with random properties in vocabulary $vid.
*/
function createTerm($vocabulary) {
+ $filter_formats = filter_formats();
+ $format = array_pop($filter_formats);
$term = entity_create('taxonomy_term', array(
'name' => $this->randomName(),
'description' => $this->randomName(),
// Use the first available text format.
- 'format' => db_query_range('SELECT format FROM {filter_format}', 0, 1)->fetchField(),
+ 'format' => $format->format,
'vid' => $vocabulary->id(),
'langcode' => LANGUAGE_NOT_SPECIFIED,
));
diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php
index 67adc3a..ec91070 100644
--- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php
+++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php
@@ -128,11 +128,13 @@ protected function mockStandardInstall() {
* The created taxonomy term.
*/
protected function createTerm() {
+ $filter_formats = filter_formats();
+ $format = array_pop($filter_formats);
$term = entity_create('taxonomy_term', array(
'name' => $this->randomName(),
'description' => $this->randomName(),
// Use the first available text format.
- 'format' => db_query_range('SELECT format FROM {filter_format}', 0, 1)->fetchField(),
+ 'format' => $format->format,
'vid' => $this->vocabulary->id(),
'langcode' => LANGUAGE_NOT_SPECIFIED,
));
diff --git a/core/modules/taxonomy/taxonomy.install b/core/modules/taxonomy/taxonomy.install
index b058409..dbaab01 100644
--- a/core/modules/taxonomy/taxonomy.install
+++ b/core/modules/taxonomy/taxonomy.install
@@ -71,7 +71,7 @@ function taxonomy_schema() {
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
- 'description' => 'The {filter_format}.format of the description.',
+ 'description' => 'The Filter Format id of the description.',
),
'weight' => array(
'type' => 'int',
diff --git a/core/modules/user/lib/Drupal/user/Tests/UserSignatureTest.php b/core/modules/user/lib/Drupal/user/Tests/UserSignatureTest.php
index 9ed88ca..3712eba 100644
--- a/core/modules/user/lib/Drupal/user/Tests/UserSignatureTest.php
+++ b/core/modules/user/lib/Drupal/user/Tests/UserSignatureTest.php
@@ -41,19 +41,19 @@ function setUp() {
// Prefetch and create text formats.
$this->plain_text_format = filter_format_load('plain_text');
- $filtered_html_format = array(
+ $filtered_html_format_config = array(
'format' => 'filtered_html',
'name' => 'Filtered HTML',
);
- $this->filtered_html_format = (object) $filtered_html_format;
- filter_format_save($this->filtered_html_format);
+ $this->filtered_html_format = entity_create('filter_format', $filtered_html_format_config);
+ $this->filtered_html_format->save();
- $full_html_format = array(
+ $full_html_format_config = array(
'format' => 'full_html',
'name' => 'Full HTML',
);
- $this->full_html_format = (object) $full_html_format;
- filter_format_save($this->full_html_format);
+ $this->full_html_format = entity_create('filter_format', $full_html_format_config);
+ $this->full_html_format->save();
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array(filter_permission_name($this->filtered_html_format)));
$this->checkPermissions(array(), TRUE);
diff --git a/core/modules/user/user.install b/core/modules/user/user.install
index 1475cda..1c90af2 100644
--- a/core/modules/user/user.install
+++ b/core/modules/user/user.install
@@ -75,7 +75,7 @@ function user_schema() {
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
- 'description' => 'The {filter_format}.format of the signature.',
+ 'description' => 'The Filter Format id of the signature.',
),
'created' => array(
'type' => 'int',
diff --git a/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php b/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php
index 1e5b72f..3a09820 100644
--- a/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php
+++ b/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php
@@ -149,11 +149,13 @@ public function testDefaultViews() {
* Returns a new term with random properties in vocabulary $vid.
*/
function createTerm($vocabulary) {
+ $filter_formats = filter_formats();
+ $format = array_pop($filter_formats);
$term = entity_create('taxonomy_term', array(
'name' => $this->randomName(),
'description' => $this->randomName(),
// Use the first available text format.
- 'format' => db_query_range('SELECT format FROM {filter_format}', 0, 1)->fetchField(),
+ 'format' => $format->format,
'vid' => $vocabulary->id(),
'langcode' => LANGUAGE_NOT_SPECIFIED,
));
diff --git a/core/modules/views/lib/Drupal/views/Tests/Handler/AreaTextTest.php b/core/modules/views/lib/Drupal/views/Tests/Handler/AreaTextTest.php
index 43b807e..312f0c4 100644
--- a/core/modules/views/lib/Drupal/views/Tests/Handler/AreaTextTest.php
+++ b/core/modules/views/lib/Drupal/views/Tests/Handler/AreaTextTest.php
@@ -34,8 +34,7 @@ public static function getInfo() {
protected function setUp() {
parent::setUp();
- $this->enableModules(array('system'));
- $this->enableModules(array('filter'));
+ $this->enableModules(array('system', 'user', 'filter'));
}
public function testAreaText() {
diff --git a/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.php b/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.php
index 79f4616..c0879eb 100644
--- a/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.php
+++ b/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.php
@@ -79,7 +79,7 @@ public static function getInfo() {
protected function setUp() {
parent::setUp();
- $this->enableModules(array('node', 'comment', 'user', 'filter'));
+ $this->enableModules(array('system', 'node', 'comment', 'user', 'filter'));
}
/**
diff --git a/core/profiles/standard/standard.install b/core/profiles/standard/standard.install
index 5cb8fb3..7f84fb4 100644
--- a/core/profiles/standard/standard.install
+++ b/core/profiles/standard/standard.install
@@ -12,62 +12,6 @@
* @see system_install()
*/
function standard_install() {
- // Add text formats.
- $filtered_html_format = array(
- 'format' => 'filtered_html',
- 'name' => 'Filtered HTML',
- 'weight' => 0,
- 'filters' => array(
- // URL filter.
- 'filter_url' => array(
- 'weight' => 0,
- 'status' => 1,
- ),
- // HTML filter.
- 'filter_html' => array(
- 'weight' => 1,
- 'status' => 1,
- ),
- // Line break filter.
- 'filter_autop' => array(
- 'weight' => 2,
- 'status' => 1,
- ),
- // HTML corrector filter.
- 'filter_htmlcorrector' => array(
- 'weight' => 10,
- 'status' => 1,
- ),
- ),
- );
- $filtered_html_format = (object) $filtered_html_format;
- filter_format_save($filtered_html_format);
-
- $full_html_format = array(
- 'format' => 'full_html',
- 'name' => 'Full HTML',
- 'weight' => 1,
- 'filters' => array(
- // URL filter.
- 'filter_url' => array(
- 'weight' => 0,
- 'status' => 1,
- ),
- // Line break filter.
- 'filter_autop' => array(
- 'weight' => 1,
- 'status' => 1,
- ),
- // HTML corrector filter.
- 'filter_htmlcorrector' => array(
- 'weight' => 10,
- 'status' => 1,
- ),
- ),
- );
- $full_html_format = (object) $full_html_format;
- filter_format_save($full_html_format);
-
// Enable Bartik theme and set it as default theme instead of Stark.
// @see system_install()
$default_theme = 'bartik';
@@ -278,6 +222,7 @@ function standard_install() {
user_install_picture_field();
// Enable default permissions for system roles.
+ $filtered_html_format = filter_format_load('filtered_html');
$filtered_html_permission = filter_permission_name($filtered_html_format);
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access content', 'access comments', $filtered_html_permission));
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('access content', 'access comments', 'post comments', 'skip comment approval', $filtered_html_permission));