0

I use Angular material in my Drupal 8 site (perforce!!!) and I have some problem with views. I want to override the output of views with custom text:

enter image description here

but as we all know views is strict with html tags and angular material uses custom directives for his purposes...

Question:

How to solve this problem?

How to make views to don't trim angular material directives?

Dose any one has solution for this?

UPDATE: The problem is that nothing is rendered correctly...

For example.

angular material card is this:

enter image description here

but the view shows this result:

enter image description here

This means that angular directives ware trimmed by Drupal, and that's why view shows incorrect result.

  • What is your problem exactly? What gets trimmed by views? – Neograph734 Sep 11 '17 at 10:45
  • You couldn't' do this with a "global" text field in Drupal 7, because it wasn't formatted text and the tags were stripped unconditionally. Looks like it's the same in Drupal 8. You'll probably have to write a custom Views extension to get that markup in there. I'd be tempted to write a simple formatted text field, copying most of it the code from the core one – Clive Sep 11 '17 at 11:14
  • thanks @Clive i see what u mean but can u pleas provide more information about your idea, or examples or is there any module for that? – George Chanturia Sep 11 '17 at 11:39
0

After a lot of research and debugging i came across to this solution...

The problem of restriction of custom text field of a view is that it uses Xss::filterAdmin function (core/modules/views/src/Plugin/views/PluginBase.php:398 line)...

So i created module, then in mymodule.views.inc file I alter "hook_views_plugins_field_alter", i changed class that uses the views custom text filed in my own class that i created in mymodule>src>plugin>views>field>my_Custom.php. This class is copy/paste of core/modules/views/src/Plugin/views/field/Custom.php and changed only the \Drupal\views\Plugin\views\PluginBase::viewsTokenReplace only this form:

$build = [
    '#type' => 'inline_template',
    '#template' => $text,
    '#context' => $twig_tokens,
    '#post_render' => [
      function ($children, $elements) {
        return Xss::filterAdmin($children);
      }
    ],
  ];

to:

 $build = [
    '#type' => 'inline_template',
    '#template' => $text,
    '#context' => $twig_tokens,
    '#post_render' => [
      function ($children, $elements) {
        return $children;
      }
    ],
  ];

and from now the custom text don't escapes html tags...

For more control i created also one checkbox in field setting to control f i want to escape the text or note for this field and accordingly to the value of checkbox i activate or deactivate the Xss::filterAdmin function

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.