/** * Implements QuickEditInPlaceEditorInterface::isCompatible(). * * @see Drupal 8's \Drupal\editor\Plugin\quickedit\editor\Editor::isCompatible(). */ public function isCompatible(array $instance, array $items) { $field = field_info_field($instance['field_name']); // This editor is incompatible with multivalued fields. if ($field['cardinality'] != 1) { return FALSE; } elseif (!empty($instance['settings']['text_processing'])) { $format_id = $items[0]['format']; if ($format = filter_format_load($format_id)) { editor_format_ensure_additional_properties($format); if ($format->editor == 'ckeditor') { return TRUE; } } return FALSE; } }
/** * Returns a fully loaded input filter structure. * * @param NodeInterface $node * @param Context $context * @return bool|\stdClass */ protected function loadExistingInputFilter(NodeInterface $node, Context $context) { $existing = filter_format_load($node->getName()); $filters = db_query("SELECT name, settings FROM {filter} WHERE format = ? AND status = 1 ORDER BY weight ASC", [$node->getName()])->fetchAllKeyed(); foreach ($filters as $name => $settings) { if (is_string($settings)) { $settings = unserialize($settings); } if (!$existing->filters) { $existing->filters = []; } if (empty($settings)) { $settings = true; } $existing->filters[$name] = $settings; } return $existing; }
/** * Makes sure that the PHP filter evaluates PHP code when used. */ function testPhpFilter() { // Log in as a user with permission to use the PHP code text format. $php_code_permission = filter_permission_name(filter_format_load('php_code')); $web_user = $this->drupalCreateUser(array('access content', 'create page content', 'edit own page content', $php_code_permission)); $this->drupalLogin($web_user); // Create a node with PHP code in it. $node = $this->createNodeWithCode(); // Make sure that the PHP code shows up as text. $this->drupalGet('node/' . $node->nid); $this->assertText('php print'); // Change filter to PHP filter and see that PHP code is evaluated. $edit = array(); $langcode = LANGUAGE_NOT_SPECIFIED; $edit["body[{$langcode}][0][format]"] = $this->php_code_format->format; $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save')); $this->assertRaw(t('Basic page %title has been updated.', array('%title' => $node->label())), 'PHP code filter turned on.'); // Make sure that the PHP code shows up as text. $this->assertNoText('print "SimpleTest PHP was executed!"', "PHP code isn't displayed."); $this->assertText('SimpleTest PHP was executed!', 'PHP code has been evaluated.'); }
function setUp() { parent::setUp(); // Create Basic page node type. $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); // Create and login admin user. $admin_user = $this->drupalCreateUser(array('administer filters')); $this->drupalLogin($admin_user); // Verify that the PHP code text format was inserted. $php_format_id = 'php_code'; $this->php_code_format = filter_format_load($php_format_id); $this->assertEqual($this->php_code_format->name, 'PHP code', 'PHP code text format was created.'); // 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.'); // Verify that the format exists on the administration page. $this->drupalGet('admin/config/content/formats'); $this->assertText('PHP code', 'PHP code text format was created.'); // Verify that anonymous and authenticated user roles do not have access. $this->drupalGet('admin/config/content/formats/' . $php_format_id); $this->assertFieldByName('roles[' . DRUPAL_ANONYMOUS_RID . ']', FALSE, 'Anonymous users do not have access to PHP code format.'); $this->assertFieldByName('roles[' . DRUPAL_AUTHENTICATED_RID . ']', FALSE, 'Authenticated users do not have access to PHP code format.'); }
/** * @Given I setup Pathologic local paths * * Save Pathologic settings for testing. */ public function pathologic_save() { $cu_path = 'testing'; $cu_sid = 'p1eb825ce549'; $pathologic_string = "/{$cu_sid}\r\n" . "/{$cu_path}\r\n" . "http://www.colorado.edu/{$cu_sid}\r\n" . "http://www.colorado.edu/{$cu_path}\r\n" . "https://www.colorado.edu/{$cu_sid}\r\n" . "https://www.colorado.edu/{$cu_path}"; $format = filter_format_load("wysiwyg"); if (empty($format->filters)) { // Get the filters used by this format. $filters = filter_list_format($format->format); // Build the $format->filters array... $format->filters = array(); foreach ($filters as $name => $filter) { foreach ($filter as $k => $v) { $format->filters[$name][$k] = $v; } } } $format->filters["pathologic"]["settings"]["local_paths"] = $pathologic_string; filter_format_save($format); }