class VimeoSettingsForm in Vimeo Video Uploader 8
Same name and namespace in other branches
- 8.4 src/Form/VimeoSettingsForm.php \Drupal\vimeo_video_uploader\Form\VimeoSettingsForm
Provide configuration form for user to provide vimeo API information for a
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\vimeo_video_uploader\Form\VimeoSettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of VimeoSettingsForm
1 string reference to 'VimeoSettingsForm'
File
- src/
Form/ VimeoSettingsForm.php, line 19 - Contains \Drupal\vimeo_video_uploader\Form\SettingsForm.
Namespace
Drupal\vimeo_video_uploader\FormView source
class VimeoSettingsForm extends ConfigFormBase {
/**
*
*/
public function __construct(ConfigFactoryInterface $config_factory, LoggerChannelFactoryInterface $logger_factory) {
$this
->setConfigFactory($config_factory);
$this->logger = $logger_factory
->get('vimeo_video_uploader');
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'vimeo_video_uploader_configuration_form';
}
/**
* {@inheritdoc}
*/
public function getEditableConfigNames() {
return [
'vimeo_video_uploader.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
// Get the configuration from ConfigFormBase::config().
$config = self::config('vimeo_video_uploader.settings');
$form['values'] = array(
'#type' => 'fieldset',
'#title' => $this
->t('VIMEO VIDEO UPLOAD CONFIGURATION'),
'#collapsible' => TRUE,
'#tree' => TRUE,
);
$form['values']['client_id'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Enter (Vimeo Client Identifier) '),
'#default_value' => $config
->get('values.client_id'),
'#required' => TRUE,
);
$form['values']['client_secret'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Enter (Vimeo Client Secrets)'),
'#default_value' => $config
->get('values.client_secret'),
'#required' => TRUE,
);
$form['values']['access_token'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Enter generated (Your new Access token)'),
'#default_value' => $config
->get('values.access_token'),
'#required' => TRUE,
);
$form['values']['content_type_select'] = array(
'#type' => 'select',
'#title' => $this
->t('Select the Content Types from which you have to upload video to Vimeo'),
'#options' => $this
->getContentTypeList(),
'#default_value' => $config
->get('values.content_type_select'),
'#required' => TRUE,
);
return parent::buildForm($form, $form_state);
}
public function getContentTypeList() {
$contentTypes = \Drupal::service('entity.manager')
->getStorage('node_type')
->loadMultiple();
$contentTypesList = [];
foreach ($contentTypes as $contentType) {
$contentTypesList[$contentType
->id()] = $contentType
->label();
}
return $contentTypesList;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Set configuration.
$config = self::config('vimeo_video_uploader.settings');
$form_state_values = $form_state
->getValues();
$message = "Saved the Vimeo configuration.";
$old_content_type_select = $config
->get('values.content_type_select');
if ($old_content_type_select !== $form_state_values['values']['content_type_select']) {
//delete some things
$entityManager = \Drupal::service('entity.manager');
$fields = $entityManager
->getFieldDefinitions('node', $old_content_type_select);
if (isset($fields['field_vimeo_file_browse']) && ($field = $fields['field_vimeo_file_browse'])) {
$field
->delete();
}
if (isset($fields['field_embeddedvideo']) && ($field1 = $fields['field_embeddedvideo'])) {
$field1
->delete();
}
$this
->AddContentTypeField($form_state_values['values']['content_type_select']);
$message = "Created 'Browse video for uploading to Vimeo' field in '" . strtoupper($form_state_values['values']['content_type_select']) . "' Content type.";
}
$config
->set('values.client_id', $form_state_values['values']['client_id'])
->set('values.client_secret', $form_state_values['values']['client_secret'])
->set('values.access_token', $form_state_values['values']['access_token'])
->set('values.content_type_select', $form_state_values['values']['content_type_select']);
$config
->save();
drupal_set_message($message, 'status');
}
function AddContentTypeField($bundle) {
\Drupal\field\Entity\FieldStorageConfig::create(array(
'field_name' => 'field_vimeo_file_browse',
'entity_type' => 'node',
'type' => 'file',
))
->save();
\Drupal\field\Entity\FieldConfig::create([
'field_name' => 'field_vimeo_file_browse',
'entity_type' => 'node',
'bundle' => $bundle,
'settings' => array(
'file_extensions' => 'mp4',
),
'label' => 'Browse video for uploading to Vimeo',
])
->save();
entity_get_form_display('node', $bundle, 'default')
->setComponent('field_vimeo_file_browse', array(
'type' => 'file_generic',
))
->save();
entity_get_display('node', $bundle, 'default')
->setComponent('field_vimeo_file_browse', array(
'type' => 'file_default',
))
->save();
//add embedded video input field
\Drupal\field\Entity\FieldStorageConfig::create(array(
'field_name' => 'field_embeddedvideo',
'entity_type' => 'node',
'type' => 'video_embed_field',
))
->save();
\Drupal\field\Entity\FieldConfig::create([
'field_name' => 'field_embeddedvideo',
'entity_type' => 'node',
'bundle' => $bundle,
'label' => 'Vimeo video link',
])
->save();
entity_get_form_display('node', $bundle, 'default')
->setComponent('field_embeddedvideo', array(
'type' => 'video_embed_field_textfield',
'class' => 'neera',
))
->save();
entity_get_display('node', $bundle, 'default')
->setComponent('field_embeddedvideo', array(
'type' => 'video_embed_field_video',
))
->save();
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('logger.factory'));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. | |
VimeoSettingsForm:: |
function | |||
VimeoSettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
VimeoSettingsForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
VimeoSettingsForm:: |
public | function | ||
VimeoSettingsForm:: |
public | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
VimeoSettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
VimeoSettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
VimeoSettingsForm:: |
public | function |
Constructs a \Drupal\system\ConfigFormBase object. Overrides ConfigFormBase:: |