class WebformShareEmbedForm in Webform 8.5
Same name and namespace in other branches
- 6.x modules/webform_share/src/Form/WebformShareEmbedForm.php \Drupal\webform_share\Form\WebformShareEmbedForm
Webform share embed form.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\webform_share\Form\WebformShareEmbedForm
Expanded class hierarchy of WebformShareEmbedForm
1 string reference to 'WebformShareEmbedForm'
- webform_share.routing.yml in modules/
webform_share/ webform_share.routing.yml - modules/webform_share/webform_share.routing.yml
File
- modules/
webform_share/ src/ Form/ WebformShareEmbedForm.php, line 15
Namespace
Drupal\webform_share\FormView source
class WebformShareEmbedForm extends FormBase {
/**
* The renderer.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* Webform request handler.
*
* @var \Drupal\webform\WebformRequestInterface
*/
protected $requestHandler;
/**
* WebformEntityReferenceLinkFormatter constructor.
*
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer.
* @param \Drupal\webform\WebformRequestInterface $request_handler
* The webform request handler.
*/
public function __construct(RendererInterface $renderer, WebformRequestInterface $request_handler) {
$this->renderer = $renderer;
$this->requestHandler = $request_handler;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('renderer'), $container
->get('webform.request'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'webform_share_embed_form';
}
/**
* Form constructor.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @return array
* The form structure.
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$webform = $this->requestHandler
->getCurrentWebform();
$source_entity = $this->requestHandler
->getCurrentSourceEntity([
'webform',
]);
$form['info'] = [
'#type' => 'webform_message',
'#message_message' => $this
->t('Choose how you want to embed the webform and then copy-n-paste the below code snippet directly into the HTML source of any webpage.'),
'#message_type' => 'info',
'#message_close' => TRUE,
'#message_storage' => WebformMessage::STORAGE_SESSION,
];
$form['type'] = [
'#type' => 'radios',
'#title' => $this
->t('Embed type'),
'#title_display' => 'invisible',
'#options' => [
'script' => $this
->t('JavaScript -- The embedded webform will be inserted using JavaScript.'),
'resizing' => $this
->t('Resizing iframe -- The embedded webform will be responsive and adjusted to fit within the page using an iframe and JavaScript.'),
'fixed' => $this
->t('Fixed iframe -- The embedded webform will be a fixed size on the page using an iframe with a scrollbar.'),
],
'#options_display' => 'buttons',
'#options_description_display' => 'help',
'#default_value' => 'script',
];
$types = [
'script' => [
'type' => 'script',
'title' => $this
->t('JavaScript code'),
],
'resizing' => [
'type' => 'iframe',
'title' => $this
->t('Resizing iframe code'),
'javascript' => TRUE,
],
'fixed' => [
'type' => 'iframe',
'title' => $this
->t('Fixed iframe code'),
],
];
foreach ($types as $type => $item) {
$build = [
'#type' => 'webform_share_' . $item['type'],
'#webform' => $webform,
'#source_entity' => $source_entity,
'#query' => $this
->getRequest()->query
->all(),
];
if (!empty($item['javascript'])) {
$build['#javascript'] = $item['javascript'];
}
$code = trim((string) $this->renderer
->renderPlain($build));
$form[$type] = [
'#type' => 'container',
'#attributes' => [
'class' => [
'js-webform-share-admin-copy',
],
],
'#states' => [
'visible' => [
':input[name="type"]' => [
'value' => $type,
],
],
],
];
$form[$type]['code'] = [
'#type' => 'webform_codemirror',
'#title' => $item['title'],
'#mode' => 'html',
'#default_value' => $code,
];
$form[$type]['copy'] = [
'#type' => 'button',
'#value' => $this
->t('Copy code'),
];
$form[$type]['message'] = [
'#markup' => $this
->t('Code copied to clipboard…'),
'#prefix' => '<strong class="webform-share-admin-copy-message">',
'#suffix' => '</strong>',
];
}
$form['#attached']['library'][] = 'webform_share/webform_share.admin';
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Do nothing.
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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 | Retrieves a configuration object. | |
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. | |
WebformShareEmbedForm:: |
protected | property | The renderer. | |
WebformShareEmbedForm:: |
protected | property | Webform request handler. | |
WebformShareEmbedForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
WebformShareEmbedForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
WebformShareEmbedForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
WebformShareEmbedForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
WebformShareEmbedForm:: |
public | function | WebformEntityReferenceLinkFormatter constructor. |