You are here

function TextWithSummaryField::ValueFromFile_ in Realistic Dummy Content 8

Given a FileGroup object, get a structured property

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

Parameters

$file: An object of type FileGroup.

Return value

Returns structured data to be added to the entity object, or NULL if such data can't be creatd.

Throws

\Exception.

Overrides Attribute::ValueFromFile_

File

api/src/attributes/TextWithSummaryField.php, line 21
Define autoload class.

Class

TextWithSummaryField
Represents the text with summary field, which must have a text format when part of an entity object. Node body is one example.

Namespace

Drupal\realistic_dummy_content_api\attributes

Code

function ValueFromFile_($file) {
  $value = $file
    ->Value();

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

  // If the value cannot be determined, which is different from an empty string.
  if ($value === NULL) {
    $return = NULL;
  }
  elseif ($value) {
    $return = array(
      \Drupal\Core\Language\Language::LANGCODE_NOT_SPECIFIED => array(
        array(
          'value' => $value,
          'format' => $format,
        ),
      ),
    );
  }
  else {
    $return = array();
  }
  return $return;
}