ViewMode.php in Search API Pages 8
File
src/Config/ViewMode.php
View source
<?php
namespace Drupal\search_api_page\Config;
class ViewMode implements ViewModeConfigInterface {
const DEFAULT_VIEW_MODE = 'default';
private $rawConfig;
public function __construct(array $rawConfig) {
$this->rawConfig = $rawConfig;
}
public function getViewMode($dataSourceId, $bundleId) {
if (!isset($this->rawConfig[$dataSourceId])) {
return self::DEFAULT_VIEW_MODE;
}
if (!$this
->hasOverrides($dataSourceId)) {
return $this
->getDefaultViewMode($dataSourceId);
}
if (!$this
->isOverridden($dataSourceId, $bundleId)) {
return $this
->getDefaultViewMode($dataSourceId);
}
return $this->rawConfig[$dataSourceId]['overrides'][$bundleId];
}
public function getDefaultViewMode($dataSourceId) {
if (!isset($this->rawConfig[$dataSourceId]['default'])) {
return self::DEFAULT_VIEW_MODE;
}
if (empty($this->rawConfig[$dataSourceId]['default'])) {
return self::DEFAULT_VIEW_MODE;
}
return $this->rawConfig[$dataSourceId]['default'];
}
public function hasOverrides($dataSourceId) {
if (!isset($this->rawConfig[$dataSourceId]['overrides'])) {
return FALSE;
}
if (empty($this->rawConfig[$dataSourceId]['overrides'])) {
return FALSE;
}
if (empty(array_filter($this->rawConfig[$dataSourceId]['overrides']))) {
return FALSE;
}
return TRUE;
}
public function isOverridden($dataSourceId, $bundleId) {
if (!$this
->hasOverrides($dataSourceId)) {
return FALSE;
}
if (!isset($this->rawConfig[$dataSourceId]['overrides'][$bundleId])) {
return FALSE;
}
if (empty($this->rawConfig[$dataSourceId]['overrides'][$bundleId])) {
return FALSE;
}
return TRUE;
}
}
Classes
Name |
Description |
ViewMode |
Value object for view mode configuration. |