class ViewMode in Search API Pages 8
Value object for view mode configuration.
Hierarchy
- class \Drupal\search_api_page\Config\ViewMode implements ViewModeConfigInterface
Expanded class hierarchy of ViewMode
2 files declare their use of ViewMode
- SearchApiPage.php in src/
Entity/ SearchApiPage.php - ViewModeTest.php in tests/
src/ Unit/ ViewModeTest.php
File
- src/
Config/ ViewMode.php, line 8
Namespace
Drupal\search_api_page\ConfigView source
class ViewMode implements ViewModeConfigInterface {
const DEFAULT_VIEW_MODE = 'default';
/**
* @var array
*/
private $rawConfig;
/**
* ViewMode constructor.
*
* @param array $rawConfig
* The raw configuration array from the configuration file.
*/
public function __construct(array $rawConfig) {
$this->rawConfig = $rawConfig;
}
/**
* {@inheritdoc}
*/
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];
}
/**
* {@inheritDoc}
*/
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'];
}
/**
* {@inheritDoc}
*/
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;
}
/**
* {@inheritDoc}
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ViewMode:: |
private | property | ||
ViewMode:: |
constant | |||
ViewMode:: |
public | function |
Gets the default view mode for a given data source. Overrides ViewModeConfigInterface:: |
|
ViewMode:: |
public | function |
Gets the configured view mode for a given data source and bundle. Overrides ViewModeConfigInterface:: |
|
ViewMode:: |
public | function |
Determines if the given data source has any view mode overrides. Overrides ViewModeConfigInterface:: |
|
ViewMode:: |
public | function |
Determines if a view mode is overridden for a given data source and bundle. Overrides ViewModeConfigInterface:: |
|
ViewMode:: |
public | function | ViewMode constructor. |