diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php b/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php index 98d15c2..30bd960 100644 --- a/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php @@ -107,7 +107,7 @@ function testGetJSSettings() { // Change the allowed HTML tags; the "format_tags" setting for CKEditor // should automatically be updated as well. $format = entity_load('filter_format', 'filtered_html'); - $format->filters['filter_html']['settings']['allowed_html'] .= '
 

'; + $format->filters('filter_html')->settings['allowed_html'] .= '
 

'; $format->save(); $expected_config['format_tags'] = 'p;h3;h4;h5;h6;pre'; $this->assertEqual($expected_config, $this->ckeditor->getJSSettings($editor), 'Generated JS settings are correct for customized configuration.'); diff --git a/core/modules/filter/config/filter.format.plain_text.yml b/core/modules/filter/config/filter.format.plain_text.yml index a7f72cd..8ce9548 100644 --- a/core/modules/filter/config/filter.format.plain_text.yml +++ b/core/modules/filter/config/filter.format.plain_text.yml @@ -15,12 +15,19 @@ filters: filter_html_escape: module: filter status: '1' + weight: '-10' + settings: { } # Convert URLs into links. filter_url: module: filter status: '1' + weight: '0' + settings: + filter_url_length: '72' # Convert linebreaks into paragraphs. filter_autop: module: filter status: '1' + weight: '0' + settings: { } langcode: und diff --git a/core/modules/filter/filter.admin.inc b/core/modules/filter/filter.admin.inc index aa3018c..a4493a9 100644 --- a/core/modules/filter/filter.admin.inc +++ b/core/modules/filter/filter.admin.inc @@ -197,25 +197,9 @@ function filter_admin_format_form($form, &$form_state, $format) { $form['roles']['#default_value'] = array($admin_role); } - // Retrieve available filters and load all configured filters for existing - // text formats. - $filter_info = filter_get_filters(); - $filters = !empty($format->format) ? filter_list_format($format->format) : array(); - - // Prepare filters for form sections. - foreach ($filter_info as $name => $filter) { - // Create an empty filter object for new/unconfigured filters. - if (!isset($filters[$name])) { - $filters[$name] = new stdClass(); - $filters[$name]->format = $format->format; - $filters[$name]->module = $filter['module']; - $filters[$name]->name = $name; - $filters[$name]->status = 0; - $filters[$name]->weight = $filter['weight']; - $filters[$name]->settings = array(); - } - } - $form['#filters'] = $filters; + // Create filter plugin instances for all available filters, including both + // enabled/configured ones as well as new and not yet unconfigured ones. + $filters = $format->filters()->sort(); // Filter status. $form['filters']['status'] = array( @@ -228,17 +212,6 @@ function filter_admin_format_form($form, &$form_state, $format) { // @see http://drupal.org/node/1829202 '#input' => FALSE, ); - foreach ($filter_info as $name => $filter) { - $form['filters']['status'][$name] = array( - '#type' => 'checkbox', - '#title' => $filter['title'], - '#default_value' => $filters[$name]->status, - '#parents' => array('filters', $name, 'status'), - '#description' => $filter['description'], - '#weight' => $filter['weight'], - ); - } - // Filter order (tabledrag). $form['filters']['order'] = array( '#type' => 'table', @@ -252,48 +225,54 @@ function filter_admin_format_form($form, &$form_state, $format) { '#input' => FALSE, '#theme_wrappers' => array('form_element'), ); - foreach ($filter_info as $name => $filter) { + // Filter settings. + $form['filter_settings'] = array( + '#type' => 'vertical_tabs', + '#title' => t('Filter settings'), + ); + + foreach ($filters as $name => $filter) { + $form['filters']['status'][$name] = array( + '#type' => 'checkbox', + '#title' => $filter->getLabel(), + '#default_value' => $filter->status, + '#parents' => array('filters', $name, 'status'), + '#description' => $filter->getDescription(), + '#weight' => $filter->weight, + ); + $form['filters']['order'][$name]['#attributes']['class'][] = 'draggable'; - $form['filters']['order'][$name]['#weight'] = $filters[$name]->weight; + $form['filters']['order'][$name]['#weight'] = $filter->weight; $form['filters']['order'][$name]['filter'] = array( - '#markup' => $filter['title'], + '#markup' => $filter->getLabel(), ); $form['filters']['order'][$name]['weight'] = array( '#type' => 'weight', - '#title' => t('Weight for @title', array('@title' => $filter['title'])), + '#title' => t('Weight for @title', array('@title' => $filter->getLabel())), '#title_display' => 'invisible', '#delta' => 50, - '#default_value' => $filters[$name]->weight, + '#default_value' => $filter->weight, '#parents' => array('filters', $name, 'weight'), '#attributes' => array('class' => array('filter-order-weight')), ); - } - // Make sure filters are in the correct order, since filter_get_filters() - // doesn't return sorted filters. - uasort($form['filters']['order'], 'element_sort'); - // Filter settings. - $form['filter_settings'] = array( - '#type' => 'vertical_tabs', - '#title' => t('Filter settings'), - ); - - foreach ($filter_info as $name => $filter) { - if (isset($filter['settings callback'])) { - $function = $filter['settings callback']; - // Pass along stored filter settings and default settings, but also the - // format object and all filters to allow for complex implementations. - $settings_form = $function($form, $form_state, $filters[$name], $format, $filter['default settings'], $filters); - if (!empty($settings_form)) { - $form['filters']['settings'][$name] = array( - '#type' => 'details', - '#title' => $filter['title'], - '#parents' => array('filters', $name, 'settings'), - '#weight' => $filter['weight'], - '#group' => 'filter_settings', - ); - $form['filters']['settings'][$name] += $settings_form; - } + // Retrieve the settings form of the filter plugin. The plugin should not be + // aware of the text format. Therefore, it only receives a set of minimal + // base properties to allow advanced implementations to work. + $settings_form = array( + '#parents' => array('filters', $name, 'settings'), + '#tree' => TRUE, + ); + $settings_form = $filter->settingsForm($settings_form, $form_state); + if (!empty($settings_form)) { + $form['filters']['settings'][$name] = array( + '#type' => 'details', + '#title' => $filter->getLabel(), + '#weight' => $filter->weight, + '#parents' => array('filters', $name, 'settings'), + '#group' => 'filter_settings', + ); + $form['filters']['settings'][$name] += $settings_form; } } @@ -337,7 +316,14 @@ function filter_admin_format_form_submit($form, &$form_state) { // Add the submitted form values to the text format, and save it. $format = $form['#format']; foreach ($form_state['values'] as $key => $value) { - $format->set($key, $value); + if ($key != 'filters') { + $format->set($key, $value); + } + else { + foreach ($value as $instance_id => $config) { + $format->setFilterConfig($instance_id, $config); + } + } } $status = $format->save(); diff --git a/core/modules/filter/filter.api.php b/core/modules/filter/filter.api.php index 49311c8..8d6aa01 100644 --- a/core/modules/filter/filter.api.php +++ b/core/modules/filter/filter.api.php @@ -11,283 +11,19 @@ */ /** - * Define content filters. - * - * User submitted content is passed through a group of filters before it is - * output in HTML, in order to remove insecure or unwanted parts, correct or - * enhance the formatting, transform special keywords, etc. A group of filters - * is referred to as a "text format". Administrators can create as many text - * formats as needed. Individual filters can be enabled and configured - * differently for each text format. - * - * This hook is invoked by filter_get_filters() and allows modules to register - * input filters they provide. - * - * Filtering is a two-step process. First, the content is 'prepared' by calling - * the 'prepare callback' function for every filter. The purpose of the - * 'prepare callback' is to escape HTML-like structures. For example, imagine a - * filter which allows the user to paste entire chunks of programming code - * without requiring manual escaping of special HTML characters like < or &. If - * the programming code were left untouched, then other filters could think it - * was HTML and change it. For many filters, the prepare step is not necessary. - * - * The second step is the actual processing step. The result from passing the - * text through all the filters' prepare steps gets passed to all the filters - * again, this time with the 'process callback' function. The process callbacks - * should then actually change the content: transform URLs into hyperlinks, - * convert smileys into images, etc. - * - * For performance reasons content is only filtered once; the result is stored - * in the cache table and retrieved from the cache the next time the same piece - * of content is displayed. If a filter's output is dynamic, it can override - * the cache mechanism, but obviously this should be used with caution: having - * one filter that does not support caching in a particular text format - * disables caching for the entire format, not just for one filter. - * - * Beware of the filter cache when developing your module: it is advised to set - * your filter to 'cache' => FALSE while developing, but be sure to remove that - * setting if it's not needed, when you are no longer in development mode. - * - * @return - * An associative array of filters, whose keys are internal filter names, - * which should be unique and therefore prefixed with the name of the module. - * Each value is an associative array describing the filter, with the - * following elements (all are optional except as noted): - * - title: (required) An administrative summary of what the filter does. - * - type: (required) A classification of the filter's purpose. This is one - * of the following: - * - FILTER_TYPE_HTML_RESTRICTOR: HTML tag and attribute restricting - * filters. - * - FILTER_TYPE_MARKUP_LANGUAGE: Non-HTML markup language filters that - * generate HTML. - * - FILTER_TYPE_TRANSFORM_IRREVERSIBLE: Irreversible transformation - * filters. - * - FILTER_TYPE_TRANSFORM_REVERSIBLE: Reversible transformation filters. - * - description: Additional administrative information about the filter's - * behavior, if needed for clarification. - * - settings callback: The name of a function that returns configuration - * form elements for the filter. See hook_filter_FILTER_settings() for - * details. - * - default settings: An associative array containing default settings for - * the filter, to be applied when the filter has not been configured yet. - * - prepare callback: The name of a function that escapes the content before - * the actual filtering happens. See hook_filter_FILTER_prepare() for - * details. - * - process callback: (required) The name the function that performs the - * actual filtering. See hook_filter_FILTER_process() for details. - * - cache (default TRUE): Specifies whether the filtered text can be cached. - * Note that setting this to FALSE makes the entire text format not - * cacheable, which may have an impact on the site's overall performance. - * See filter_format_allowcache() for details. - * - tips callback: The name of a function that returns end-user-facing - * filter usage guidelines for the filter. See hook_filter_FILTER_tips() - * for details. - * - weight: A default weight for the filter in new text formats. - * - * @see filter_example.module - * @see hook_filter_info_alter() - */ -function hook_filter_info() { - $filters['filter_html'] = array( - 'title' => t('Limit allowed HTML tags'), - 'type' => FILTER_TYPE_HTML_RESTRICTOR, - 'description' => t('Allows you to restrict the HTML tags the user can use. It will also remove harmful content such as JavaScript events, JavaScript URLs and CSS styles from those tags that are not removed.'), - 'process callback' => '_filter_html', - 'settings callback' => '_filter_html_settings', - 'default settings' => array( - 'allowed_html' => '

'; + $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 .= '
'; + $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.'); + } + } + +} diff --git a/core/modules/php/lib/Drupal/php/Tests/PhpTestBase.php b/core/modules/php/lib/Drupal/php/Tests/PhpTestBase.php index abb3412..c18273a 100644 --- a/core/modules/php/lib/Drupal/php/Tests/PhpTestBase.php +++ b/core/modules/php/lib/Drupal/php/Tests/PhpTestBase.php @@ -40,7 +40,7 @@ function setUp() { // Verify that the format has the PHP code filter enabled. $filters = filter_list_format($php_format_id); - $this->assertTrue($filters['php_code']->status, 'PHP code filter is enabled.'); + $this->assertTrue($filters->get('php_code')->status, 'PHP code filter is enabled.'); // Verify that the format exists on the administration page. $this->drupalGet('admin/config/content/formats'); diff --git a/core/modules/php/php.module b/core/modules/php/php.module index e31b4c5..02fd1dd 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 theme 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/text/lib/Drupal/text/Tests/TextSummaryTest.php b/core/modules/text/lib/Drupal/text/Tests/TextSummaryTest.php index f679109..aec92e0 100644 --- a/core/modules/text/lib/Drupal/text/Tests/TextSummaryTest.php +++ b/core/modules/text/lib/Drupal/text/Tests/TextSummaryTest.php @@ -7,13 +7,14 @@ namespace Drupal\text\Tests; -use Drupal\simpletest\WebTestBase; +use Drupal\simpletest\DrupalUnitTestBase; /** * Tests the text field summary. */ -class TextSummaryTest extends WebTestBase { - protected $profile = 'standard'; +class TextSummaryTest extends DrupalUnitTestBase { + + public static $modules = array('system', 'user', 'filter', 'text'); public static function getInfo() { return array( @@ -25,7 +26,10 @@ public static function getInfo() { function setUp() { parent::setUp(); - $this->article_creator = $this->drupalCreateUser(array('create article content', 'edit own article content')); + + $this->installSchema('system', 'url_alias'); + $this->installSchema('user', 'role_permission'); + $this->installConfig(array('text')); } /** @@ -36,7 +40,7 @@ function setUp() { function testFirstSentenceQuestion() { $text = 'A question? A sentence. Another sentence.'; $expected = 'A question? A sentence.'; - $this->callTextSummary($text, $expected, NULL, 30); + $this->assertTextSummary($text, $expected, NULL, 30); } /** @@ -51,133 +55,174 @@ function testLongSentence() { 'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ' . 'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.'; // First three sentences add up to: 336, so add one for space and then 3 to get half-way into next word. - $this->callTextSummary($text, $expected, NULL, 340); + $this->assertTextSummary($text, $expected, NULL, 340); } /** * Test various summary length edge cases. */ function testLength() { + entity_create('filter_format', array( + 'format' => 'autop', + 'filters' => array( + 'filter_autop' => array( + 'status' => 1, + ), + ), + ))->save(); + entity_create('filter_format', array( + 'format' => 'autop_correct', + 'filters' => array( + 'filter_autop' => array( + 'status' => 1, + ), + 'filter_htmlcorrector' => array( + 'status' => 1, + ), + ), + ))->save(); + // This string tests a number of edge cases. $text = "

\nHi\n

\n

\nfolks\n
\n!\n

"; // The summaries we expect text_summary() to return when $size is the index // of each array item. // Using no text format: - $expected = array( - "

\nHi\n

\n

\nfolks\n
\n!\n

", - "<", - "", - "

\n", - "

\nH", - "

\nHi", - "

\nHi\n", - "

\nHi\n<", - "

\nHi\n\nHi\n\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

\n

\nfolks\n
\n!\n

", - "

\nHi\n

\n

\nfolks\n
\n!\n

", - "

\nHi\n

\n

\nfolks\n
\n!\n

", - ); + $format = NULL; + $i = 0; + $this->assertTextSummary($text, "

\nHi\n

\n

\nfolks\n
\n!\n

", $format, $i++); + $this->assertTextSummary($text, "<", $format, $i++); + $this->assertTextSummary($text, "assertTextSummary($text, "

", $format, $i++); + $this->assertTextSummary($text, "

\n", $format, $i++); + $this->assertTextSummary($text, "

\nH", $format, $i++); + $this->assertTextSummary($text, "

\nHi", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n<", $format, $i++); + $this->assertTextSummary($text, "

\nHi\nassertTextSummary($text, "

\nHi\nassertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

\n

\nfolks\n
\n!\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

\n

\nfolks\n
\n!\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

\n

\nfolks\n
\n!\n

", $format, $i++); - // And using a text format WITH the line-break and htmlcorrector filters. - $expected_lb = array( - "

\nHi\n

\n

\nfolks\n
\n!\n

", - "", - "

", - "

", - "

", - "

", - "

", - "

\nHi

", - "

\nHi

", - "

\nHi

", - "

\nHi

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

\n

\nfolks\n
\n!\n

", - "

\nHi\n

\n

\nfolks\n
\n!\n

", - "

\nHi\n

\n

\nfolks\n
\n!\n

", - ); + // Using a text format with filter_autop enabled. + $format = 'autop'; + $i = 0; + $this->assertTextSummary($text, "

\nHi\n

\n

\nfolks\n
\n!\n

", $format, $i++); + $this->assertTextSummary($text, "<", $format, $i++); + $this->assertTextSummary($text, "assertTextSummary($text, "

", $format, $i++); + $this->assertTextSummary($text, "

", $format, $i++); + $this->assertTextSummary($text, "

", $format, $i++); + $this->assertTextSummary($text, "

", $format, $i++); + $this->assertTextSummary($text, "

\nHi", $format, $i++); + $this->assertTextSummary($text, "

\nHi", $format, $i++); + $this->assertTextSummary($text, "

\nHi", $format, $i++); + $this->assertTextSummary($text, "

\nHi", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

\n

\nfolks\n
\n!\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

\n

\nfolks\n
\n!\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

\n

\nfolks\n
\n!\n

", $format, $i++); - // Test text_summary() for different sizes. - for ($i = 0; $i <= 37; $i++) { - $this->callTextSummary($text, $expected[$i], NULL, $i); - $this->callTextSummary($text, $expected_lb[$i], 'plain_text', $i); - $this->callTextSummary($text, $expected_lb[$i], 'basic_html', $i); - } + // Using a text format with filter_autop and filter_htmlcorrector enabled. + $format = 'autop_correct'; + $i = 0; + $this->assertTextSummary($text, "

\nHi\n

\n

\nfolks\n
\n!\n

", $format, $i++); + $this->assertTextSummary($text, "", $format, $i++); + $this->assertTextSummary($text, "

", $format, $i++); + $this->assertTextSummary($text, "

", $format, $i++); + $this->assertTextSummary($text, "

", $format, $i++); + $this->assertTextSummary($text, "

", $format, $i++); + $this->assertTextSummary($text, "

", $format, $i++); + $this->assertTextSummary($text, "

\nHi

", $format, $i++); + $this->assertTextSummary($text, "

\nHi

", $format, $i++); + $this->assertTextSummary($text, "

\nHi

", $format, $i++); + $this->assertTextSummary($text, "

\nHi

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

\n

\nfolks\n
\n!\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

\n

\nfolks\n
\n!\n

", $format, $i++); + $this->assertTextSummary($text, "

\nHi\n

\n

\nfolks\n
\n!\n

", $format, $i++); } /** * Calls text_summary() and asserts that the expected teaser is returned. */ - function callTextSummary($text, $expected, $format = NULL, $size = NULL) { + function assertTextSummary($text, $expected, $format = NULL, $size = NULL) { $summary = text_summary($text, $format, $size); - $this->assertIdentical($summary, $expected, t('Generated summary "@summary" matches expected "@expected".', array('@summary' => $summary, '@expected' => $expected))); + $this->assertIdentical($summary, $expected, format_string('
@actual
is identical to
@expected
', array( + '@actual' => $summary, + '@expected' => $expected, + ))); } - /** - * Test sending only summary. - */ - function testOnlyTextSummary() { - // Login as article creator. - $this->drupalLogin($this->article_creator); - // Create article with summary but empty body. - $summary = $this->randomName(); - $edit = array( - "title" => $this->randomName(), - "body[und][0][summary]" => $summary, - ); - $this->drupalPost('node/add/article', $edit, t('Save')); - $node = $this->drupalGetNodeByTitle($edit['title']); - - $this->assertIdentical($node->body['und'][0]['summary'], $summary, 'Article with with summary and no body has been submitted.'); - } } diff --git a/core/modules/text/text.module b/core/modules/text/text.module index 4bf51b6..4fe2115 100644 --- a/core/modules/text/text.module +++ b/core/modules/text/text.module @@ -272,16 +272,24 @@ function text_summary($text, $format = NULL, $size = NULL) { return substr($text, 0, $delimiter); } - // We check for the presence of the PHP evaluator filter in the current - // format. If the body contains PHP code, we do not split it up to prevent - // parse errors. + // Retrieve the filters of the specified text format, if any. if (isset($format)) { $filters = filter_list_format($format); - if (isset($filters['php_code']) && $filters['php_code']->status && strpos($text, 'has('php_code') && $filters->get('php_code')->status && strpos($text, '' => 6, '
' => 4); // Newline only indicates a line break if line break converter // filter is present. - if (isset($filters['filter_autop'])) { + if (isset($format) && $filters->has('filter_autop') && $filters->get('filter_autop')->status) { $line_breaks["\n"] = 1; } $break_points[] = $line_breaks; @@ -344,7 +352,7 @@ function text_summary($text, $format = NULL, $size = NULL) { } // If the htmlcorrector filter is present, apply it to the generated summary. - if (isset($filters['filter_htmlcorrector'])) { + if (isset($format) && $filters->has('filter_htmlcorrector') && $filters->get('filter_htmlcorrector')->status) { $summary = _filter_htmlcorrector($summary); } diff --git a/core/profiles/standard/config/filter.format.basic_html.yml b/core/profiles/standard/config/filter.format.basic_html.yml index e97db8d..8685b20 100644 --- a/core/profiles/standard/config/filter.format.basic_html.yml +++ b/core/profiles/standard/config/filter.format.basic_html.yml @@ -9,13 +9,19 @@ filters: filter_html: module: filter status: '1' + weight: '-10' settings: allowed_html: '