You are here

FormatterBase.php in Facebook Instant Articles 3.x

Same filename and directory in other branches
  1. 8.2 src/Plugin/Field/FieldFormatter/FormatterBase.php

File

src/Plugin/Field/FieldFormatter/FormatterBase.php
View source
<?php

namespace Drupal\fb_instant_articles\Plugin\Field\FieldFormatter;

use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase as DrupalFormatterBase;
use Drupal\fb_instant_articles\Plugin\Field\InstantArticleFormatterInterface;

/**
 * Base class for all of our FBIA field formatters.
 */
abstract class FormatterBase extends DrupalFormatterBase implements InstantArticleFormatterInterface {
  const SOURCE_TYPE_URL = 'url';
  const SOURCE_TYPE_HTML = 'html';

  /**
   * {@inheritdoc}
   */
  public function viewElements(FieldItemListInterface $items, $langcode) {

    // Do nothing. Our field formatters are unique in that they are not meant
    // to generate HTML on their own, but only signal to the Serialization API
    // the fate of this field in the FBIA document.
    return [];
  }

}

Classes

Namesort descending Description
FormatterBase Base class for all of our FBIA field formatters.