X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fvideo%2Fsrc%2FPlugin%2FField%2FFieldWidget%2FVideoEmbedWidget.php;fp=web%2Fmodules%2Fcontrib%2Fvideo%2Fsrc%2FPlugin%2FField%2FFieldWidget%2FVideoEmbedWidget.php;h=2f4d0d27419b7c86b990be05819f03016fdc5075;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website
diff --git a/web/modules/contrib/video/src/Plugin/Field/FieldWidget/VideoEmbedWidget.php b/web/modules/contrib/video/src/Plugin/Field/FieldWidget/VideoEmbedWidget.php
new file mode 100644
index 000000000..2f4d0d274
--- /dev/null
+++ b/web/modules/contrib/video/src/Plugin/Field/FieldWidget/VideoEmbedWidget.php
@@ -0,0 +1,431 @@
+ 'video-thumbnails/[date:custom:Y]-[date:custom:m]',
+ 'allowed_providers' => ["youtube" => "youtube"],
+ 'uri_scheme' => 'public'
+ );
+ return $settings;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function settingsForm(array $form, FormStateInterface $form_state) {
+ $element = array();
+ $settings = $this->getSettings();
+ $provider_manager = \Drupal::service('video.provider_manager');
+ $element['allowed_providers'] = [
+ '#title' => t('Video Providers'),
+ '#type' => 'checkboxes',
+ '#default_value' => $this->getSetting('allowed_providers'),
+ '#options' => $provider_manager->getProvidersOptionList(),
+ ];
+ $element['file_directory'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Thumbnail directory'),
+ '#default_value' => $settings['file_directory'],
+ '#description' => t('Optional subdirectory within the upload destination where files will be stored. Do not include preceding or trailing slashes.'),
+ '#element_validate' => array(array(get_class($this), 'validateDirectory')),
+ '#weight' => 3,
+ );
+ $scheme_options = \Drupal::service('stream_wrapper_manager')->getNames(StreamWrapperInterface::WRITE_VISIBLE);
+ $element['uri_scheme'] = array(
+ '#type' => 'radios',
+ '#title' => t('Thumbnail destination'),
+ '#options' => $scheme_options,
+ '#default_value' => $this->getSetting('uri_scheme'),
+ '#description' => t('Select where the final files should be stored. Private file storage has significantly more overhead than public files, but allows restricted access to files within this field.'),
+ '#weight' => 6,
+ );
+ return $element;
+ }
+
+ /**
+ * Form API callback
+ *
+ * Removes slashes from the beginning and end of the destination value and
+ * ensures that the file directory path is not included at the beginning of the
+ * value.
+ *
+ * This function is assigned as an #element_validate callback in
+ * settingsForm().
+ */
+ public static function validateDirectory($element, FormStateInterface $form_state) {
+ // Strip slashes from the beginning and end of $element['file_directory'].
+ $value = trim($element['#value'], '\\/');
+ $form_state->setValueForElement($element, $value);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function settingsSummary() {
+ $summary = array();
+ $summary[] = t('Providers : @allowed_providers
Thumbnail directory : @file_directory',
+ array(
+ '@allowed_providers' => implode(', ', array_filter($this->getSetting('allowed_providers'))),
+ '@file_directory' => $this->getSetting('uri_scheme') . '://' . $this->getSetting('file_directory'),
+ ));
+ return $summary;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function formMultipleElements(FieldItemListInterface $items, array &$form, FormStateInterface $form_state) {
+ $field_name = $this->fieldDefinition->getName();
+ $cardinality = $this->fieldDefinition->getFieldStorageDefinition()->getCardinality();
+ $parents = $form['#parents'];
+
+ // Load the items for form rebuilds from the field state as they might not
+ // be in $form_state->getValues() because of validation limitations. Also,
+ // they are only passed in as $items when editing existing entities.
+ $field_state = static::getWidgetState($parents, $field_name, $form_state);
+ if (isset($field_state['items'])) {
+ $items->setValue($field_state['items']);
+ }
+
+ // Determine the number of widgets to display.
+ switch ($cardinality) {
+ case FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED:
+ $field_state = static::getWidgetState($parents, $field_name, $form_state);
+ $max = $field_state['items_count'];
+ $is_multiple = TRUE;
+ break;
+
+ default:
+ $max = $cardinality - 1;
+ $is_multiple = ($cardinality > 1);
+ break;
+ }
+
+ $title = $this->fieldDefinition->getLabel();
+ $description = FieldFilteredMarkup::create(\Drupal::token()->replace($this->fieldDefinition->getDescription()));
+
+ $elements = array();
+
+ for ($delta = 0; $delta <= $max; $delta++) {
+ // Add a new empty item if it doesn't exist yet at this delta.
+ if (!isset($items[$delta])) {
+ $items->appendItem();
+ }
+
+ // For multiple fields, title and description are handled by the wrapping
+ // table.
+ if ($is_multiple) {
+ $element = [
+ '#title' => $this->t('@title (value @number)', ['@title' => $title, '@number' => $delta + 1]),
+ '#title_display' => 'invisible',
+ '#description' => '',
+ ];
+ }
+ else {
+ $element = [
+ '#title' => $title,
+ '#title_display' => 'before',
+ '#description' => $description,
+ ];
+ }
+
+ $element = $this->formSingleElement($items, $delta, $element, $form, $form_state);
+
+ if ($element) {
+ // Input field for the delta (drag-n-drop reordering).
+ if ($is_multiple) {
+ // We name the element '_weight' to avoid clashing with elements
+ // defined by widget.
+ $element['_weight'] = array(
+ '#type' => 'weight',
+ '#title' => $this->t('Weight for row @number', array('@number' => $delta + 1)),
+ '#title_display' => 'invisible',
+ // Note: this 'delta' is the FAPI #type 'weight' element's property.
+ '#delta' => $max,
+ '#default_value' => $items[$delta]->_weight ? : $delta,
+ '#weight' => 100,
+ );
+ }
+
+ $elements[$delta] = $element;
+ }
+ }
+
+ if ($elements) {
+ $elements += array(
+ '#theme' => 'field_multiple_value_form',
+ '#field_name' => $field_name,
+ '#cardinality' => $cardinality,
+ '#cardinality_multiple' => $this->fieldDefinition->getFieldStorageDefinition()->isMultiple(),
+ '#required' => $this->fieldDefinition->isRequired(),
+ '#title' => $title,
+ '#description' => $description,
+ '#max_delta' => $max,
+ );
+
+ // Add 'add more' button, if not working with a programmed form.
+ if ($cardinality == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED && !$form_state->isProgrammed()) {
+ $id_prefix = implode('-', array_merge($parents, array($field_name)));
+ $wrapper_id = Html::getUniqueId($id_prefix . '-add-more-wrapper');
+ // $elements['#prefix'] = '