DsFieldBase.php in Display Suite 8.2
File
src/Plugin/DsField/DsFieldBase.php
View source
<?php
namespace Drupal\ds\Plugin\DsField;
use Drupal\Core\Plugin\PluginBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class DsFieldBase extends PluginBase implements DsFieldInterface {
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->configuration += $this
->defaultConfiguration();
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition);
}
public function build() {
return array();
}
public function settingsForm($form, FormStateInterface $form_state) {
return array();
}
public function settingsSummary($settings) {
return array();
}
public function defaultConfiguration() {
return array();
}
public function getConfiguration() {
return $this->configuration;
}
public function setConfiguration(array $configuration) {
$this->configuration = $configuration + $this->configuration;
}
public function formatters() {
return array();
}
public function isAllowed() {
$definition = $this
->getPluginDefinition();
if (!isset($definition['ui_limit'])) {
return TRUE;
}
$limits = $definition['ui_limit'];
foreach ($limits as $limit) {
if (strpos($limit, '|') !== FALSE) {
list($bundle_limit, $view_mode_limit) = explode('|', $limit);
if (($bundle_limit == $this
->bundle() || $bundle_limit == '*') && ($view_mode_limit == $this
->viewMode() || $view_mode_limit == '*')) {
return TRUE;
}
}
}
return FALSE;
}
public function entity() {
return $this->configuration['entity'];
}
public function getEntityTypeId() {
if (isset($this->configuration['entity_type'])) {
return $this->configuration['entity_type'];
}
elseif ($entity = $this
->entity()) {
return $entity
->getEntityTypeId();
}
else {
return '';
}
}
public function bundle() {
return $this->configuration['bundle'];
}
public function viewMode() {
return $this->configuration['view_mode'];
}
public function getFieldConfiguration() {
return $this->configuration['field'];
}
public function getName() {
return $this->configuration['field_name'];
}
public function getTitle() {
return $this->configuration['field']['title'];
}
public function calculateDependencies() {
return array();
}
public function isMultiple() {
return FALSE;
}
}