You are here

class FieldsPluginOptions in Layout Plugin Views 8

Same name and namespace in other branches
  1. 8.2 src/FieldsPluginOptions.php \Drupal\layout_plugin_views\FieldsPluginOptions

Hierarchy

Expanded class hierarchy of FieldsPluginOptions

1 file declares its use of FieldsPluginOptions
Fields.php in src/Plugin/views/row/Fields.php

File

src/FieldsPluginOptions.php, line 9

Namespace

Drupal\layout_plugin_views
View source
class FieldsPluginOptions {

  /**
   * @var \Drupal\layout_plugin_views\Plugin\views\row\Fields
   */
  private $plugin;

  /**
   * @var \Drupal\layout_plugin\Plugin\Layout\LayoutPluginManagerInterface
   */
  private $layoutPluginManager;
  public static function fromFieldsPlugin(LayoutPluginManagerInterface $layoutPluginManager, Fields $plugin) {
    return new static($layoutPluginManager, $plugin);
  }
  private function __construct(LayoutPluginManagerInterface $layoutPluginManager, Fields $plugin) {
    $this->plugin = $plugin;
    $this->layoutPluginManager = $layoutPluginManager;
  }

  /**
   * Retrieves the machine name of the selected layout.
   *
   * @return string
   */
  public function getLayout() {
    return $this->plugin->options['layout'];
  }

  /**
   * Retrieves the machine name of the region set to be the default region.
   *
   * @return string
   */
  public function getDefaultRegion() {
    return $this->plugin->options['default_region'];
  }

  /**
   * Retrieves the region machine name that was assigned to the given field.
   *
   * @param string $field_machine_name
   *
   * @return string
   *  The machine name of the region that the given field is assigned to or an
   *  empty string if the field is not assigned to a region.
   */
  public function getAssignedRegion($field_machine_name) {
    if (isset($this->plugin->options['assigned_regions'][$field_machine_name])) {
      return $this->plugin->options['assigned_regions'][$field_machine_name];
    }
    else {
      return '';
    }
  }

  /**
   * @return bool
   */
  public function hasValidSelectedLayout() {
    return $this->layoutPluginManager
      ->hasDefinition($this
      ->getLayout());
  }

  /**
   * Retrieves the definition of the selected layout.
   *
   * @return array
   */
  public function getSelectedLayoutDefinition() {
    return $this
      ->hasValidSelectedLayout() ? $this->layoutPluginManager
      ->getDefinition($this
      ->getLayout()) : [];
  }

  /**
   * @return bool
   */
  public function layoutFallbackIsPossible() {
    return count($this->layoutPluginManager
      ->getDefinitions()) > 0;
  }

  /**
   * @return array
   */
  public function getFallbackLayoutDefinition() {
    $definitions = $this->layoutPluginManager
      ->getDefinitions();
    return array_shift($definitions);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FieldsPluginOptions::$layoutPluginManager private property
FieldsPluginOptions::$plugin private property
FieldsPluginOptions::fromFieldsPlugin public static function
FieldsPluginOptions::getAssignedRegion public function Retrieves the region machine name that was assigned to the given field.
FieldsPluginOptions::getDefaultRegion public function Retrieves the machine name of the region set to be the default region.
FieldsPluginOptions::getFallbackLayoutDefinition public function
FieldsPluginOptions::getLayout public function Retrieves the machine name of the selected layout.
FieldsPluginOptions::getSelectedLayoutDefinition public function Retrieves the definition of the selected layout.
FieldsPluginOptions::hasValidSelectedLayout public function
FieldsPluginOptions::layoutFallbackIsPossible public function
FieldsPluginOptions::__construct private function