You are here

RealisticDummyContentTextWithSummaryField.php in Realistic Dummy Content 3.x

File

api/src/includes/RealisticDummyContentTextWithSummaryField.php
View source
<?php

namespace Drupal\realistic_dummy_content_api\includes;

use Drupal\realistic_dummy_content_api\Framework\Framework;

/**
 * Represents the text with summary field.
 *
 * This field must have a text format when part of an entity object. Node body
 * is one example.
 */
class RealisticDummyContentTextWithSummaryField extends RealisticDummyContentField {

  /**
   * {@inheritdoc}
   */
  public function implementValueFromFile($file) : array {
    $value = $file
      ->Value();

    // @TODO use the site's default, not Framework::instance()->filteredHtml(), as the
    // default format.
    $format = $file
      ->Attribute('format', Framework::instance()
      ->filteredHtml());

    // If the value cannot be determined, which is different from an empty
    // string.
    if ($value === NULL) {
      return [];
    }
    if ($value) {
      $return = Framework::instance()
        ->formatProperty('text_with_summary', $value, [
        'format' => $format,
      ]);
      return $return;
    }
    else {
      return [];
    }
  }

}

Classes

Namesort descending Description
RealisticDummyContentTextWithSummaryField Represents the text with summary field.