FieldsPluginOptions.php in Layout Plugin Views 8
File
src/FieldsPluginOptions.php
View source
<?php
namespace Drupal\layout_plugin_views;
use Drupal\layout_plugin\Plugin\Layout\LayoutPluginManagerInterface;
use Drupal\layout_plugin_views\Plugin\views\row\Fields;
class FieldsPluginOptions {
private $plugin;
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;
}
public function getLayout() {
return $this->plugin->options['layout'];
}
public function getDefaultRegion() {
return $this->plugin->options['default_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 '';
}
}
public function hasValidSelectedLayout() {
return $this->layoutPluginManager
->hasDefinition($this
->getLayout());
}
public function getSelectedLayoutDefinition() {
return $this
->hasValidSelectedLayout() ? $this->layoutPluginManager
->getDefinition($this
->getLayout()) : [];
}
public function layoutFallbackIsPossible() {
return count($this->layoutPluginManager
->getDefinitions()) > 0;
}
public function getFallbackLayoutDefinition() {
$definitions = $this->layoutPluginManager
->getDefinitions();
return array_shift($definitions);
}
}