FieldFormatterConditionBase.php in Field Formatter Condition 8
File
src/Plugin/FieldFormatterConditionBase.php
View source
<?php
namespace Drupal\fico\Plugin;
use Drupal\Component\Plugin\PluginBase;
use Drupal\field\FieldConfigInterface;
abstract class FieldFormatterConditionBase extends PluginBase implements FieldFormatterConditionInterface {
public function getDefinition($plugin_id, $exception_on_invalid = TRUE) {
}
public function getDefinitions() {
}
public function hasDefinition($plugin_id) {
}
public function createInstance($plugin_id, array $configuration = []) {
}
public function getInstance(array $options) {
}
public abstract function alterForm(&$form, $settings);
public abstract function access(&$build, $field, $settings);
public abstract function summary($settings);
protected function getEntityType(array $build) {
if (isset($build['#entity_type'])) {
return $build['#entity_type'];
}
$types = \Drupal::entityManager()
->getDefinitions();
foreach ($types as $id => $type) {
if (!is_a($type, 'Drupal\\Core\\Entity\\ContentEntityType')) {
continue;
}
if (isset($build['#' . $id])) {
return $id;
}
}
return NULL;
}
protected function getEntity(array $build) {
if (!($type = $this
->getEntityType($build))) {
return FALSE;
}
return is_object($build['#' . $this
->getEntityType($build)]) ? $build['#' . $this
->getEntityType($build)] : NULL;
}
protected function getEntityFields($entity_type, $bundle) {
$fields = [];
$entityManager = \Drupal::service('entity.manager');
if (!empty($entity_type) && !empty($bundle)) {
$fields = array_filter($entityManager
->getFieldDefinitions($entity_type, $bundle), function ($field_definition) {
return $field_definition instanceof FieldConfigInterface;
});
}
return $fields;
}
}