VideoEmbedField.php in Video Embed Field 8.2
File
src/Plugin/Field/FieldType/VideoEmbedField.php
View source
<?php
namespace Drupal\video_embed_field\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\Core\TypedData\TraversableTypedDataInterface;
class VideoEmbedField extends FieldItemBase {
protected $providerManager;
public function __construct($definition, $name = NULL, TraversableTypedDataInterface $parent = NULL, $provider_manager = NULL) {
parent::__construct($definition, $name, $parent);
$this->providerManager = $provider_manager;
}
public static function createInstance($definition, $name = NULL, TraversableTypedDataInterface $parent = NULL) {
$provider_manager = \Drupal::service('video_embed_field.provider_manager');
return new static($definition, $name, $parent, $provider_manager);
}
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return [
'columns' => [
'value' => [
'type' => 'varchar',
'length' => 256,
],
],
];
}
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties['value'] = DataDefinition::create('string')
->setLabel(t('Video url'))
->setRequired(TRUE);
return $properties;
}
public function isEmpty() {
$value = $this
->get('value')
->getValue();
return empty($value);
}
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
$form = [];
$form['allowed_providers'] = [
'#title' => $this
->t('Allowed Providers'),
'#description' => $this
->t('Restrict users from entering information from the following providers. If none are selected any video provider can be used.'),
'#type' => 'checkboxes',
'#default_value' => $this
->getSetting('allowed_providers'),
'#options' => $this->providerManager
->getProvidersOptionList(),
];
return $form;
}
public static function defaultFieldSettings() {
return [
'allowed_providers' => [],
];
}
}