class CKEditorMediaEmbedSettingsForm in CKEditor Media Embed Plugin 8
Class CKEditorMediaEmbedSettingsForm.
@package Drupal\ckeditor_media_embed\Form
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\ckeditor_media_embed\Form\CKEditorMediaEmbedSettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of CKEditorMediaEmbedSettingsForm
1 string reference to 'CKEditorMediaEmbedSettingsForm'
File
- src/
Form/ CKEditorMediaEmbedSettingsForm.php, line 21
Namespace
Drupal\ckeditor_media_embed\FormView source
class CKEditorMediaEmbedSettingsForm extends ConfigFormBase {
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandler
*/
protected $moduleHandler;
/**
* The URL generator.
*
* @var \Drupal\Core\Routing\UrlGeneratorInterface
*/
protected $urlGenerator;
/**
* The library discovery service.
*
* @var \Drupal\Core\Asset\LibraryDiscoveryInterface
*/
protected $libraryDiscovery;
/**
* Constructs a \Drupal\system\ConfigFormBase object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
* @param \Drupal\Core\Extension\ModuleHandler $module_handler
* The module handler.
* @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator
* The URL generator.
* @param \Drupal\Core\Asset\LibraryDiscoveryInterface $library_discovery
* The library discovery service to use for retrieving information about
* the CKeditor library.
*/
public function __construct(ConfigFactoryInterface $config_factory, ModuleHandler $module_handler, UrlGeneratorInterface $url_generator, LibraryDiscoveryInterface $library_discovery) {
parent::__construct($config_factory);
$this->urlGenerator = $url_generator;
$this->moduleHandler = $module_handler;
$this->libraryDiscovery = $library_discovery;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('module_handler'), $container
->get('url_generator'), $container
->get('library.discovery'));
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'ckeditor_media_embed.settings',
];
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'ckeditor_media_embed_settings_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('ckeditor_media_embed.settings');
$version = AssetManager::getCKEditorVersion($this->libraryDiscovery, $this->configFactory);
if (!AssetManager::pluginsAreInstalled($version)) {
$this
->messenger()
->addWarning(_ckeditor_media_embed_get_install_instructions());
return [];
}
$form['embed_provider'] = [
'#type' => 'textfield',
'#title' => $this
->t('Provider URL'),
'#default_value' => $config
->get('embed_provider'),
'#description' => $this
->t('A template for the URL of the provider endpoint.
This URL will be queried for each resource to be embedded. By default CKEditor uses the Iframely service.<br />
<em>Note that if you wish to support HTTPS with Iframely then you must create an account. Please read their <a href="https://iframely.com/docs/ckeditor">documentation</a> for more details.</em><br />
<strong>Example</strong> <code>//example.com/api/oembed-proxy?resource-url={url}&callback={callback}&api_token=MYAPITOKEN</code><br />
<strong>Default</strong> <code>http://ckeditor.iframe.ly/api/oembed?url={url}&callback={callback}</code>
<br />
'),
];
if ($this->moduleHandler
->moduleExists('help')) {
$form['embed_provider']['#description'] .= $this
->t('Check out the <a href=":help">help</a> page for more information.<br />', [
':help' => $this->urlGenerator
->generateFromRoute('help.page', [
'name' => 'ckeditor_media_embed',
]),
]);
}
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
$embed_provider = $form_state
->getValue('embed_provider');
$this
->prepareEmbedProviderValidation($embed_provider);
if (!UrlHelper::isValid($embed_provider, TRUE)) {
$form_state
->setErrorByName('embed_provider', $this
->t('The provider url was not valid.'));
}
}
/**
* Prepare the embed provider setting for validation.
*
* @param string $embed_provider
* The embed provider that should be prepared for validation.
*
* @return $this
*/
protected function prepareEmbedProviderValidation(&$embed_provider) {
if (strpos($embed_provider, '//') === 0) {
$embed_provider = 'http:' . $embed_provider;
}
$embed_provider = str_replace('{url}', '', $embed_provider);
$embed_provider = str_replace('{callback}', '', $embed_provider);
return $this;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$this
->config('ckeditor_media_embed.settings')
->set('embed_provider', $form_state
->getValue('embed_provider'))
->save();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CKEditorMediaEmbedSettingsForm:: |
protected | property | The library discovery service. | |
CKEditorMediaEmbedSettingsForm:: |
protected | property | The module handler. | |
CKEditorMediaEmbedSettingsForm:: |
protected | property |
The URL generator. Overrides UrlGeneratorTrait:: |
|
CKEditorMediaEmbedSettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
CKEditorMediaEmbedSettingsForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
CKEditorMediaEmbedSettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
CKEditorMediaEmbedSettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
CKEditorMediaEmbedSettingsForm:: |
protected | function | Prepare the embed provider setting for validation. | |
CKEditorMediaEmbedSettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
CKEditorMediaEmbedSettingsForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
CKEditorMediaEmbedSettingsForm:: |
public | function |
Constructs a \Drupal\system\ConfigFormBase object. Overrides ConfigFormBase:: |
|
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. | |
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 | 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. |