You are here

public function CourseHandler::setOption in Course 8.2

Same name and namespace in other branches
  1. 8.3 src/Helper/CourseHandler.php \Drupal\course\Helper\CourseHandler::setOption()
  2. 3.x src/Helper/CourseHandler.php \Drupal\course\Helper\CourseHandler::setOption()

Set an option for this handler.

Parameters

string $option: An option key.

mixed $value: The option value.

Return value

CourseHandler

11 calls to CourseHandler::setOption()
CourseHandler::setOptions in src/Helper/CourseHandler.php
Set this entire handler's options.
CourseObject::getTitle in src/Entity/CourseObject.php
CourseObject::save in src/Entity/CourseObject.php
Apply configuration from session and let objects create their instances before saving the course object.
CourseObject::setComponent in src/Entity/CourseObject.php
Set the object component for this course object.
CourseObject::setCourse in src/Entity/CourseObject.php
Set the Course for this CourseObject.

... See full list

File

src/Helper/CourseHandler.php, line 99

Class

CourseHandler
Master class for a course related content entity.

Namespace

Drupal\course\Helper

Code

public function setOption($option, $value) {
  $defs = $this
    ->getFieldDefinitions();
  foreach ($defs as $field_name => $def) {
    if ($def
      ->getType() == 'map') {
      $map_field = $field_name;
    }
  }
  if (!isset($defs[$option]) && isset($map_field)) {

    // Not a core field.
    if (array_key_exists($option, $this
      ->optionsDefinition())) {
      $map = $this
        ->get($map_field)
        ->getValue();
      $map[0][$option] = $value;
      $this
        ->set($map_field, $map);
    }
  }
  else {
    $this
      ->set($option, $value);
  }
  return $this;
}