예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function process($text, $langcode)
 {
     $result = new FilterProcessResult($text);
     // Track if widget has been found so that we can attached the
     // jquery_ui_filter library and settings.
     $has_widget = FALSE;
     foreach (self::$widgets as $name => $widget) {
         if (strpos($text, '[' . $name) === FALSE) {
             continue;
         }
         $has_widget = TRUE;
         // Remove block tags around tokens.
         $text = preg_replace('#<(p|div)[^>]*>\\s*(\\[/?' . $name . '[^]]*\\])\\s*</\\1>#', '\\2', $text);
         // Convert opening [token] to opening <div data-ui-*> tag.
         $text = preg_replace_callback('#\\[' . $name . '([^]]*)?\\]#is', function ($match) use($name) {
             // Set data-ui-* attributes from role and options.
             $attributes = new Attribute(['data-ui-role' => $name]);
             $options = $this->parseOptions($match[1]);
             foreach ($options as $name => $value) {
                 $attributes->setAttribute('data-ui-' . $name, $value);
             }
             return "<div{$attributes}>";
         }, $text);
         // Convert closing [/token] to closing </div> tag.
         $text = str_replace('[/' . $name . ']', '</div>', $text);
     }
     if ($has_widget) {
         $result->setAttachments(['library' => ['jquery_ui_filter/jquery_ui_filter'], 'drupalSettings' => ['jquery_ui_filter' => \Drupal::config('jquery_ui_filter.settings')->get()]]);
     }
     return $result->setProcessedText($text);
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode = NULL)
 {
     $output = [];
     $attributes = new Attribute();
     if ($this->getSetting('tag') == 'h1') {
         $attributes->addClass('title');
         $attributes->addClass('replaced-title');
         $attributes->setAttribute('id', 'page-title');
     }
     $parent = $items->getParent()->getValue();
     foreach ($items as $item) {
         $text = $item->getValue()['value'];
         if ($this->getSetting('linked')) {
             $text = $this->l($text, $parent->urlInfo());
         }
         $output[] = $build['string'] = ['#type' => 'inline_template', '#template' => '<{{ tag }} {{ attributes }}>{{ text }}</{{ tag }}>', '#context' => ['text' => $text, 'tag' => $this->getSetting('tag'), 'attributes' => (string) $attributes]];
     }
     return $output;
 }
예제 #3
0
 /**
  * Render the taxonomy tree.
  *
  * @param string $vid
  *   Vocabulary id.
  * @param string $name
  *   An optional name for the tree. (Default: NULL).
  * @param string $description
  *   $description An optional description of the tree. (Default: NULL).
  *
  * @return string
  *   A string representing a rendered tree.
  */
 public function getTaxonomyTree($vid, $name = NULL, $description = NULL)
 {
     $output = '';
     $options = array();
     $attributes = new Attribute();
     $config = \Drupal::config('sitemap.settings');
     if (\Drupal::service('module_handler')->moduleExists('forum') && $vid == \Drupal::config('forum.settings')->get('vocabulary')) {
         $title = \Drupal::l($name, Url::fromRoute('forum.index'));
         $threshold = $config->get('forum_threshold');
         $forum_link = TRUE;
     } else {
         $title = $name;
         $threshold = $config->get('term_threshold');
         $forum_link = FALSE;
     }
     $last_depth = -1;
     $output .= !empty($description) && $config->get('show_description') ? '<div class="description">' . Xss::filterAdmin($description) . "</div>\n" : '';
     $depth = $config->get('vocabulary_depth');
     if ($depth <= -1) {
         $depth = NULL;
     }
     $tree = \Drupal::entityManager()->getStorage('taxonomy_term')->loadTree($vid, 0, $depth);
     foreach ($tree as $term) {
         $term->count = sitemap_taxonomy_term_count_nodes($term->tid);
         if ($term->count <= $threshold) {
             continue;
         }
         // Adjust the depth of the <ul> based on the change
         // in $term->depth since the $last_depth.
         if ($term->depth > $last_depth) {
             for ($i = 0; $i < $term->depth - $last_depth; $i++) {
                 $output .= "\n<ul>";
             }
         } elseif ($term->depth == $last_depth) {
             $output .= '</li>';
         } elseif ($term->depth < $last_depth) {
             for ($i = 0; $i < $last_depth - $term->depth; $i++) {
                 $output .= "</li>\n</ul>\n</li>";
             }
         }
         // Display the $term.
         $output .= "\n<li>";
         $term_item = '';
         if ($forum_link) {
             $term_item .= \Drupal::l($term->name, Url::fromRoute('forum.page', array('taxonomy_term' => $term->tid), array('attributes' => array('title' => $term->description__value))));
         } elseif ($term->count) {
             $term_item .= \Drupal::l($term->name, Url::fromRoute('entity.taxonomy_term.canonical', array('taxonomy_term' => $term->tid), array('attributes' => array('title' => $term->description__value))));
         } else {
             $term_item .= $term->name;
         }
         if ($config->get('show_count')) {
             $span_title = \Drupal::translation()->formatPlural($term->count, '1 item has this term', '@count items have this term');
             $term_item .= " <span title=\"" . $span_title . "\">(" . $term->count . ")</span>";
         }
         // RSS depth.
         $rss_depth = $config->get('rss_taxonomy');
         if ($config->get('show_rss_links') != 0 && ($rss_depth == -1 || $term->depth < $rss_depth)) {
             $feed_icon = array('#theme' => 'sitemap_feed_icon', '#url' => 'taxonomy/term/' . $term->tid . '/feed', '#name' => $term->name);
             $rss_link = drupal_render($feed_icon);
             if ($config->get('show_rss_links') == 1) {
                 $term_item .= ' ' . $rss_link;
             } else {
                 $attributes->addClass('sitemap-rss-left');
                 $term_item = $rss_link . ' ' . $term_item;
             }
         }
         // Add an alter hook for modules to manipulate the taxonomy term output.
         \Drupal::moduleHandler()->alter(array('sitemap_taxonomy_term', 'sitemap_taxonomy_term_' . $term->tid), $term_item, $term);
         $output .= $term_item;
         // Reset $last_depth in preparation for the next $term.
         $last_depth = $term->depth;
     }
     // Bring the depth back to where it began, -1.
     if ($last_depth > -1) {
         for ($i = 0; $i < $last_depth + 1; $i++) {
             $output .= "</li>\n</ul>\n";
         }
     }
     $this->setOption($options, 'show_titles', 1, 'show_titles', TRUE);
     $attributes->addClass('sitemap-box-terms', 'sitemap-box-terms-' . $vid);
     $sitemap_box = array('title' => $title, 'content' => array('#markup' => $output), 'attributes' => $attributes, 'options' => $options);
     return $sitemap_box;
 }
 public static function iframe_iframe($text, $path, $item)
 {
     $options = array();
     $options['width'] = !empty($item->width) ? $item->width : '100%';
     $options['height'] = !empty($item->height) ? $item->height : '701';
     if (!empty($item->frameborder) && $item->frameborder > 0) {
         $options['frameborder'] = (int) $item->frameborder;
     }
     $options['scrolling'] = !empty($item->scrolling) ? $item->scrolling : 'auto';
     if (!empty($item->transparency) && $item->transparency > 0) {
         $options['transparency'] = (int) $item->transparency;
     }
     $htmlid = '';
     if (isset($item->htmlid) && !empty($item->htmlid)) {
         $htmlid = ' id="' . htmlspecialchars($item->htmlid) . '" name="' . htmlspecialchars($item->htmlid) . '"';
     }
     // Append active class.
     $options['class'] = !empty($item->class) ? $item->class : '';
     /*
     if ($path == $_GET['q'] || ($path == '<front>' && drupal_is_front_page())) {
       if (!empty($options['class'])) {
         $options['class'] .= ' active';
       }
       else {
         $options['class'] = 'active';
       }
     }
     */
     // Remove all HTML and PHP tags from a tooltip. For best performance, we act only
     // if a quick strpos() pre-check gave a suspicion (because strip_tags() is expensive).
     $options['title'] = !empty($item->title) ? $item->title : '';
     if (!empty($options['title']) && strpos($options['title'], '<') !== FALSE) {
         $options['title'] = strip_tags($options['title']);
     }
     $options_link = array();
     $options_link['attributes'] = array();
     $options_link['attributes']['title'] = $options['title'];
     $drupal_attributes = new Attribute($options);
     if (\Drupal::moduleHandler()->moduleExists('token')) {
         // Token Support for field "url" and "title"
         $tokensupport = !empty($item->tokensupport) && $item->tokensupport >= 0 ? (int) $item->tokensupport : 0;
         if ($tokensupport > 0) {
             $text = \Drupal::token()->replace($text, array('node' => $GLOBALS['node'], 'user' => \Drupal::currentUser()));
         }
         if ($tokensupport > 1) {
             $path = \Drupal::token()->replace($path, array('node' => $GLOBALS['node'], 'user' => \Drupal::currentUser()));
         }
     }
     $output = '<div class="' . (!empty($options['class']) ? \Drupal\Component\Utility\SafeMarkup::checkPlain($options['class']) : '') . '">' . (empty($text) ? '' : '<h3 class="iframe_title">' . (isset($options['html']) && $options['html'] ? $text : \Drupal\Component\Utility\SafeMarkup::checkPlain($text)) . '</h3>') . '<iframe src="' . htmlspecialchars(Url::fromUri($path, $options)->toString()) . '"' . $drupal_attributes->__toString() . $htmlid . '>' . t('Your browser does not support iframes. But You can use the following link.') . ' ' . \Drupal::l('Link', Url::fromUri($path, $options_link)) . '</iframe>' . '</div>';
     return $output;
 }
예제 #5
0
 /**
  * Tests the storage method.
  */
 public function testStorage()
 {
     $attribute = new Attribute(array('class' => array('example-class')));
     $this->assertEquals(array('class' => new AttributeArray('class', array('example-class'))), $attribute->storage());
 }