You are here

public function RealisticDummyContentTextWithSummaryField::implementValueFromFile in Realistic Dummy Content 3.x

Same name and namespace in other branches
  1. 8.2 api/src/includes/RealisticDummyContentTextWithSummaryField.php \Drupal\realistic_dummy_content_api\includes\RealisticDummyContentTextWithSummaryField::implementValueFromFile()
  2. 7.2 api/src/includes/RealisticDummyContentTextWithSummaryField.php \Drupal\realistic_dummy_content_api\includes\RealisticDummyContentTextWithSummaryField::implementValueFromFile()

Given a RealisticDummyContentFileGroup object, get a structured property.

This function is not meant to called directly; rather, call ValueFromFile(). This function must be overriden by subclasses.

Parameters

object $file: An object of type RealisticDummyContentFileGroup.

Return value

array Returns structured data to be added to the entity object, or an empty array if such data can't be created.

Throws

\Exception.

Overrides RealisticDummyContentAttribute::implementValueFromFile

File

api/src/includes/RealisticDummyContentTextWithSummaryField.php, line 18

Class

RealisticDummyContentTextWithSummaryField
Represents the text with summary field.

Namespace

Drupal\realistic_dummy_content_api\includes

Code

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 [];
  }
}