MediaTypeBase.php in Media entity 8
File
src/MediaTypeBase.php
View source
<?php
namespace Drupal\media_entity;
use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\Config\Config;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Component\Utility\NestedArray;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Form\FormStateInterface;
abstract class MediaTypeBase extends PluginBase implements MediaTypeInterface, ContainerFactoryPluginInterface {
use StringTranslationTrait;
protected $label;
protected $entityTypeManager;
protected $entityFieldManager;
protected $config;
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityFieldManagerInterface $entity_field_manager, Config $config) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
$this->entityFieldManager = $entity_field_manager;
$this->config = $config;
$this
->setConfiguration($configuration);
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager'), $container
->get('entity_field.manager'), $container
->get('config.factory')
->get('media_entity.settings'));
}
public function setConfiguration(array $configuration) {
$this->configuration = NestedArray::mergeDeep($this
->defaultConfiguration(), $configuration);
}
public function getConfiguration() {
return $this->configuration;
}
public function defaultConfiguration() {
return [];
}
public function getDefaultThumbnail() {
return '';
}
public function label() {
return $this->label;
}
public function attachConstraints(MediaInterface $media) {
}
public function calculateDependencies() {
return [];
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
return [];
}
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
}
public function getDefaultName(MediaInterface $media) {
return 'media:' . $media
->bundle() . ':' . $media
->uuid();
}
}