/** * {@inheritdoc} */ public function process($text, $langcode) { $result = new FilterProcessResult($text); $result->addCacheTags(array('foo:bar')); $result->addCacheTags(array('foo:baz')); return $result; }
/** * {@inheritdoc} */ public function process($text, $langcode) { $result = new FilterProcessResult($text); if (stristr($text, 'data-entity-type="file"') !== FALSE) { $dom = Html::load($text); $xpath = new \DOMXPath($dom); $processed_uuids = array(); foreach ($xpath->query('//*[@data-entity-type="file" and @data-entity-uuid]') as $node) { $uuid = $node->getAttribute('data-entity-uuid'); // If there is a 'src' attribute, set it to the file entity's current // URL. This ensures the URL works even after the file location changes. if ($node->hasAttribute('src')) { $file = $this->entityManager->loadEntityByUuid('file', $uuid); if ($file) { $node->setAttribute('src', file_url_transform_relative(file_create_url($file->getFileUri()))); } } // Only process the first occurrence of each file UUID. if (!isset($processed_uuids[$uuid])) { $processed_uuids[$uuid] = TRUE; $file = $this->entityManager->loadEntityByUuid('file', $uuid); if ($file) { $result->addCacheTags($file->getCacheTags()); } } } $result->setProcessedText(Html::serialize($dom)); } return $result; }
/** * {@inheritdoc} */ public function process($text, $langcode) { $result = new FilterProcessResult($text); if (stristr($text, 'data-entity-type="file"') !== FALSE) { $dom = Html::load($text); $xpath = new \DOMXPath($dom); $processed_uuids = array(); foreach ($xpath->query('//*[@data-entity-type="file" and @data-entity-uuid]') as $node) { $uuid = $node->getAttribute('data-entity-uuid'); // Only process the first occurrence of each file UUID. if (!isset($processed_uuids[$uuid])) { $processed_uuids[$uuid] = TRUE; $file = $this->entityManager->loadEntityByUuid('file', $uuid); if ($file) { $result->addCacheTags($file->getCacheTags()); } } } } return $result; }
/** * {@inheritdoc} */ public function process($text, $langcode) { $result = new FilterProcessResult($text); try { // Load GeSHi library (if not already). $geshi_library = libraries_load('geshi'); if (!$geshi_library['loaded']) { throw new \Exception($geshi_library['error message']); } // Get the available tags. list($generic_code_tags, $language_tags, $tag_to_lang) = $this->getTags(); if (in_array(GeshiFilter::BRACKETS_PHPBLOCK, array_filter($this->tagStyles()))) { $language_tags[] = 'questionmarkphp'; $tag_to_lang['questionmarkphp'] = 'php'; } $tags = array_merge($generic_code_tags, $language_tags); // Escape special (regular expression) characters in tags (for tags like // 'c++' and 'c#'). $tags = preg_replace('#(\\+|\\#)#', '\\\\$1', $tags); $tags_string = implode('|', $tags); // Pattern for matching the prepared "<code>...</code>" stuff. $pattern = '#\\[geshifilter-(' . $tags_string . ')([^\\]]*)\\](.*?)(\\[/geshifilter-\\1\\])#s'; $text = preg_replace_callback($pattern, array($this, 'replaceCallback'), $text); // Create the object with result. $result = new FilterProcessResult($text); // Add the css file when necessary. if ($this->config->get('css_mode') == GeshiFilter::CSS_CLASSES_AUTOMATIC) { $result->setAttachments(array('library' => array('geshifilter/geshifilter'))); } // Add cache tags, so we can re-create the node when some geshifilter // settings change. $cache_tags = array('geshifilter'); $result->addCacheTags($cache_tags); } catch (\Exception $e) { watchdog_exception('geshifilter', $e); drupal_set_message($geshi_library['error message'], 'error'); } return $result; }