You are here

class ConfigurableContentLoader in YAML Content 8.2

A ContentLoader implementation supporting configuration options.

@todo Use service parameter for override-able default options.

Hierarchy

Expanded class hierarchy of ConfigurableContentLoader

See also

\Drupal\yaml_content\ContentLoader\ContentLoaderInterface

\Drupal\yaml_content\ContentLoader\ContentLoaderBase

1 string reference to 'ConfigurableContentLoader'
yaml_content.services.yml in ./yaml_content.services.yml
yaml_content.services.yml
1 service uses ConfigurableContentLoader
yaml_content.content_loader in ./yaml_content.services.yml
Drupal\yaml_content\ContentLoader\ConfigurableContentLoader

File

src/ContentLoader/ConfigurableContentLoader.php, line 17

Namespace

Drupal\yaml_content\ContentLoader
View source
class ConfigurableContentLoader extends ContentLoaderBase implements ContentLoaderInterface {

  /**
   * A collection of configurable options affecting execution behavior.
   *
   * @var array
   */
  protected $options;

  /**
   * {@inheritdoc}
   */
  public function __construct(EntityTypeManagerInterface $entityTypeManager, SerializationInterface $parser, EventDispatcherInterface $dispatcher) {
    parent::__construct($entityTypeManager, $parser, $dispatcher);

    // Initialize with default configuration options.
    $this->options = $this
      ->getDefaultOptions();
  }

  /**
   * Set a configurable option value.
   *
   * @param string $option
   *   The name of the option being configured.
   * @param mixed $value
   *   The value to assign into the option.
   *
   * @return \Drupal\yaml_content\ContentLoader\ContentLoaderInterface
   *   The called object.
   */
  public function setOption($option, $value) {
    $this->options[$option] = $value;
    return $this;
  }

  /**
   * Get the value from a configured option.
   *
   * @param string $option
   *   The name of the option value to retrieve.
   *
   * @return mixed|null
   *   The value of the specified option or NULL if the option is unset.
   */
  public function getOption($option) {
    $value = NULL;
    if (isset($this->options[$option])) {
      $value = $this->options[$option];
    }
    return $value;
  }

  /**
   * Fetch all configured options.
   *
   * @return array
   *   All configured options for this ContentLoader.
   */
  public function getOptions() {
    return $this->options + $this
      ->getDefaultOptions();
  }

  /**
   * Set multiple configuration options.
   *
   * @param array $options
   *   A collection of configuration values to assign. These are used to
   *   override currently set or default values.
   *
   * @return $this
   *   The called object.
   */
  public function setOptions(array $options) {
    $this->options = $options + $this->options + $this
      ->getDefaultOptions();
    return $this;
  }

  /**
   * Fetch all default configuration options.
   *
   * @return array
   *   A collection of all default options for this ContentLoader.
   *
   * @todo Integrate default options with service parameters.
   */
  public function getDefaultOptions() {
    return [];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigurableContentLoader::$options protected property A collection of configurable options affecting execution behavior.
ConfigurableContentLoader::getDefaultOptions public function Fetch all default configuration options.
ConfigurableContentLoader::getOption public function Get the value from a configured option.
ConfigurableContentLoader::getOptions public function Fetch all configured options.
ConfigurableContentLoader::setOption public function Set a configurable option value.
ConfigurableContentLoader::setOptions public function Set multiple configuration options.
ConfigurableContentLoader::__construct public function Constructs a ContentLoaderBase object. Overrides ContentLoaderBase::__construct
ContentLoaderBase::$contentFile protected property The file path for the content file currently being loaded.
ContentLoaderBase::$dispatcher protected property Event dispatcher service to report events throughout the loading process.
ContentLoaderBase::$entityTypeManager protected property Entity type manager service to dynamically handle entities.
ContentLoaderBase::$parsedContent protected property The array of content parsed from the content file being loaded.
ContentLoaderBase::$parser protected property Content file parser utility.
ContentLoaderBase::$path protected property The file path where content files should be loaded from.
ContentLoaderBase::assignFieldValue public function Set or assign a field value based on field cardinality.
ContentLoaderBase::buildEntity public function Build an entity from the provided content data. Overrides ContentLoaderInterface::buildEntity
ContentLoaderBase::importEntity public function Load an entity from a loaded import data outline. 1
ContentLoaderBase::importEntityField public function Process import data into an appropriate field value and assign it. 1
ContentLoaderBase::importFieldItem public function Process import data for an individual field list item value. 1
ContentLoaderBase::loadContent public function Load all demo content for a set of parsed data. Overrides ContentLoaderInterface::loadContent 1
ContentLoaderBase::loadContentBatch public function Load a batch of content files. Overrides ContentLoaderInterface::loadContentBatch
ContentLoaderBase::parseContent public function Parse the given yaml content file into an array. Overrides ContentLoaderInterface::parseContent
ContentLoaderBase::setContentPath public function Set a path prefix for all content files to be loaded from.