You are here

protected function SubtitleFormatter::getTransformer in Facebook Instant Articles 3.x

Get a transformer with a custom rule set specifically for subtitles.

Return value

\Facebook\InstantArticles\Transformer\Transformer Transformer with our ruleset for subtitles.

Throws

\ReflectionException

1 call to SubtitleFormatter::getTransformer()
SubtitleFormatter::viewInstantArticle in src/Plugin/Field/FieldFormatter/SubtitleFormatter.php
Modifies the given instant article with the contents of this field.

File

src/Plugin/Field/FieldFormatter/SubtitleFormatter.php, line 153

Class

SubtitleFormatter
Plugin implementation of the 'fbia_subtitle' formatter.

Namespace

Drupal\fb_instant_articles\Plugin\Field\FieldFormatter

Code

protected function getTransformer() : Transformer {
  $transformer = $this->transformerFactory
    ->getTransformer();
  $transformer
    ->setRules([
    TextNodeRule::createFrom([]),
    PassThroughRule::createFrom([
      'selector' => '//html|//body|//p|//div|//blockquote|//h1|//h2|//h3|//h4',
    ]),
    ItalicRule::createFrom([
      'selector' => 'i',
    ]),
    ItalicRule::createFrom([
      'selector' => 'em',
    ]),
    BoldRule::createFrom([
      'selector' => 'b',
    ]),
    BoldRule::createFrom([
      'selector' => 'strong',
    ]),
    AnchorRule::createFrom([
      'selector' => 'a',
      'properties' => [
        AnchorRule::PROPERTY_ANCHOR_HREF => [
          'type' => 'string',
          'selector' => 'a',
          'attribute' => 'href',
        ],
        AnchorRule::PROPERTY_ANCHOR_REL => [
          'type' => 'string',
          'selector' => 'a',
          'attribute' => 'rel',
        ],
      ],
    ]),
  ]);
  return $transformer;
}