You are here

abstract class YamlFormManagedFileBase in YAML Form 8

Provides a base class form 'managed_file' elements.

Hierarchy

Expanded class hierarchy of YamlFormManagedFileBase

File

src/Plugin/YamlFormElement/YamlFormManagedFileBase.php, line 23

Namespace

Drupal\yamlform\Plugin\YamlFormElement
View source
abstract class YamlFormManagedFileBase extends YamlFormElementBase {

  /**
   * {@inheritdoc}
   */
  public function getDefaultProperties() {
    $max_filesize = \Drupal::config('yamlform.settings')
      ->get('file.default_max_filesize') ?: file_upload_max_size();
    $max_filesize = Bytes::toInt($max_filesize);
    $max_filesize = $max_filesize / 1024 / 1024;
    $file_extensions = $this
      ->getFileExtensions();
    return parent::getDefaultProperties() + [
      'multiple' => FALSE,
      'max_filesize' => $max_filesize,
      'file_extensions' => $file_extensions,
      'uri_scheme' => 'private',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function hasMultipleValues(array $element) {
    return !empty($element['#multiple']) ? TRUE : FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function isMultiline(array $element) {
    if ($this
      ->hasMultipleValues($element)) {
      return TRUE;
    }
    else {
      return parent::isMultiline($element);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function isEnabled() {
    if (!parent::isEnabled()) {
      return FALSE;
    }

    // Disable managed file element is there are no visible stream wrappers.
    $scheme_options = self::getVisibleStreamWrappers();
    return empty($scheme_options) ? FALSE : TRUE;
  }

  /**
   * {@inheritdoc}
   */
  public function displayDisabledWarning(array $element) {

    // Display standard disabled element warning.
    if (!parent::isEnabled()) {
      parent::displayDisabledWarning($element);
    }
    else {

      // Display 'managed_file' stream wrappers warning.
      $scheme_options = self::getVisibleStreamWrappers();
      $uri_scheme = $this
        ->getUriScheme($element);
      if (!isset($scheme_options[$uri_scheme]) && $this->currentUser
        ->hasPermission('administer yamlform')) {
        drupal_set_message($this
          ->t('The \'Managed file\' element is unavailable because a <a href="https://www.drupal.org/documentation/modules/file">private files directory</a> has not been configured and public file uploads have not been enabled. For more information see: <a href="https://www.drupal.org/psa-2016-003">DRUPAL-PSA-2016-003</a>'), 'warning');
        $context = [
          'link' => Link::fromTextAndUrl($this
            ->t('Edit'), \Drupal\Core\Url::fromRoute('<current>'))
            ->toString(),
        ];
        $this->logger
          ->notice("The 'Managed file' element is unavailable because no stream wrappers are available", $context);
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public function prepare(array &$element, YamlFormSubmissionInterface $yamlform_submission) {
    parent::prepare($element, $yamlform_submission);

    // Check if the URI scheme exists and can be used the upload location.
    $scheme_options = self::getVisibleStreamWrappers();
    $uri_scheme = $this
      ->getUriScheme($element);
    if (!isset($scheme_options[$uri_scheme])) {
      $element['#access'] = FALSE;
      $this
        ->displayDisabledWarning($element);
    }
    else {
      $element['#upload_location'] = $this
        ->getUploadLocation($element, $yamlform_submission
        ->getYamlForm());
    }
    $element['#upload_validators']['file_validate_size'] = [
      $this
        ->getMaxFileSize($element),
    ];
    $element['#upload_validators']['file_validate_extensions'] = [
      $this
        ->getFileExtensions($element),
    ];

    // Use custom validation callback so that File entities can be converted
    // into file ids (akk fids).
    $element['#element_validate'][] = [
      get_class($this),
      'validate',
    ];

    // Add file upload help to the element.
    $element['help'] = [
      '#theme' => 'file_upload_help',
      '#description' => '',
      '#upload_validators' => $element['#upload_validators'],
      '#cardinality' => empty($element['#multiple']) ? 1 : -1,
      '#prefix' => '<div class="description">',
      '#suffix' => '</div>',
    ];
  }

  /**
   * {@inheritdoc}
   */
  protected function prepareWrapper(array &$element) {
    parent::prepareWrapper($element);

    // Issue #2705471: Form states managed file fields.
    // Workaround: Wrap the 'managed_file' element in a basic container.
    if (!empty($element['#fixed_wrapper']) || empty($element['#prefix'])) {
      return;
    }
    $container = [
      '#prefix' => $element['#prefix'],
      '#suffix' => $element['#suffix'],
    ];
    unset($element['#prefix'], $element['#suffix']);
    $container[$element['#yamlform_key']] = $element + [
      '#fixed_wrapper' => TRUE,
    ];
    $element = $container;
  }

  /**
   * {@inheritdoc}
   */
  public function setDefaultValue(array &$element) {
    if (!empty($element['#default_value']) && !is_array($element['#default_value'])) {
      $element['#default_value'] = [
        $element['#default_value'],
      ];
    }
  }

  /**
   * {@inheritdoc}
   */
  public function formatHtml(array &$element, $value, array $options = []) {
    if (empty($value)) {
      return '';
    }
    $items = $this
      ->formatItems($element, $value, $options);
    if (empty($items)) {
      return '';
    }
    if ($this
      ->hasMultipleValues($element)) {
      return [
        '#theme' => 'item_list',
        '#items' => $items,
      ];
    }
    else {
      return reset($items);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function formatText(array &$element, $value, array $options = []) {
    if (empty($value)) {
      return '';
    }
    if (empty($element['#format']) || $element['#format'] == 'link') {
      $element['#format'] = 'url';
    }
    $items = $this
      ->formatItems($element, $value, $options);
    if (empty($items)) {
      return '';
    }

    // Add dash (aka bullet) before each item.
    if ($this
      ->hasMultipleValues($element)) {
      foreach ($items as &$item) {
        $item = '- ' . $item;
      }
    }
    return implode("\n", $items);
  }

  /**
   * Format a managed files as array of strings.
   *
   * @param array $element
   *   An element.
   * @param array|mixed $value
   *   A value.
   * @param array $options
   *   An array of options.
   *
   * @return array
   *   Managed files as array of strings.
   */
  protected function formatItems(array &$element, $value, array $options) {
    $fids = is_array($value) ? $value : [
      $value,
    ];
    $files = File::loadMultiple($fids);
    $format = $this
      ->getFormat($element);
    $items = [];
    foreach ($files as $fid => $file) {
      switch ($format) {
        case 'link':
          $items[$fid] = [
            '#theme' => 'file_link',
            '#file' => $file,
          ];
          break;
        case 'id':
          $items[$fid] = $file
            ->id();
          break;
        case 'url':
        case 'value':
        case 'raw':
          $items[$fid] = file_create_url($file
            ->getFileUri());
          break;
        default:
          $theme = str_replace('yamlform_', 'yamlform_element_', $this
            ->getPluginId());
          if (strpos($theme, 'yamlform_') !== 0) {
            $theme = 'yamlform_element_' . $theme;
          }
          $items[$fid] = [
            '#theme' => $theme,
            '#element' => $element,
            '#value' => $value,
            '#options' => $options,
            '#file' => $file,
          ];
          break;
      }
    }
    return $items;
  }

  /**
   * {@inheritdoc}
   */
  public function getDefaultFormat() {
    return 'file';
  }

  /**
   * {@inheritdoc}
   */
  public function getFormats() {
    return parent::getFormats() + [
      'file' => $this
        ->t('File'),
      'link' => $this
        ->t('Link'),
      'id' => $this
        ->t('File ID'),
      'url' => $this
        ->t('URL'),
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getElementSelectorOptions(array $element) {
    $title = $this
      ->getAdminLabel($element);
    $name = $element['#yamlform_key'];
    return [
      ":input[name=\"files[{$name}]\"]" => $title . '  [' . $this
        ->getPluginLabel() . ']',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function postSave(array &$element, YamlFormSubmissionInterface $yamlform_submission, $update = TRUE) {

    // Get current value and original value for this element.
    $key = $element['#yamlform_key'];
    $original_data = $yamlform_submission
      ->getOriginalData();
    $data = $yamlform_submission
      ->getData();
    $value = isset($data[$key]) ? $data[$key] : [];
    $fids = is_array($value) ? $value : [
      $value,
    ];
    $original_value = isset($original_data[$key]) ? $original_data[$key] : [];
    $original_fids = is_array($original_value) ? $original_value : [
      $original_value,
    ];

    // Check the original submission fids and delete the old file upload.
    foreach ($original_fids as $original_fid) {
      if (!in_array($original_fid, $fids)) {
        file_delete($original_fid);
      }
    }

    // Exit if there is no fids.
    if (empty($fids)) {
      return;
    }
    $files = File::loadMultiple($fids);
    foreach ($files as $file) {
      $source_uri = $file
        ->getFileUri();

      // Replace /_sid_/ token with the submission id.
      if (strpos($source_uri, '/_sid_/')) {
        $destination_uri = str_replace('/_sid_/', '/' . $yamlform_submission
          ->id() . '/', $source_uri);
        $destination_directory = \Drupal::service('file_system')
          ->dirname($destination_uri);
        file_prepare_directory($destination_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
        $destination_uri = file_unmanaged_move($source_uri, $destination_uri);

        // Update the file's uri and save.
        $file
          ->setFileUri($destination_uri);
        $file
          ->save();
      }

      // Update file usage table.
      // Set file usage which will also make the file's status permanent.

      /** @var \Drupal\file\FileUsage\FileUsageInterface $file_usage */
      $file_usage = \Drupal::service('file.usage');
      $file_usage
        ->delete($file, 'yamlform', 'yamlform_submission', $yamlform_submission
        ->id(), 0);
      $file_usage
        ->add($file, 'yamlform', 'yamlform_submission', $yamlform_submission
        ->id());
    }
  }

  /**
   * {@inheritdoc}
   */
  public function postDelete(array &$element, YamlFormSubmissionInterface $yamlform_submission) {
    $yamlform = $yamlform_submission
      ->getYamlForm();
    $data = $yamlform_submission
      ->getData();
    $key = $element['#yamlform_key'];
    $value = isset($data[$key]) ? $data[$key] : [];
    $fids = is_array($value) ? $value : [
      $value,
    ];

    // Delete managed file record.
    foreach ($fids as $fid) {
      file_delete($fid);
    }

    // Remove the empty directory for all stream wrappers.
    $stream_wrappers = array_keys(\Drupal::service('stream_wrapper_manager')
      ->getNames(StreamWrapperInterface::WRITE_VISIBLE));
    foreach ($stream_wrappers as $stream_wrapper) {
      file_unmanaged_delete_recursive($stream_wrapper . '://yamlform/' . $yamlform
        ->id() . '/' . $yamlform_submission
        ->id());
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getTestValue(array $element, YamlFormInterface $yamlform) {
    if ($this
      ->isDisabled()) {
      return NULL;
    }
    $file_extensions = explode(' ', $this
      ->getFileExtensions($element));
    $file_extension = $file_extensions[array_rand($file_extensions)];
    $upload_location = $this
      ->getUploadLocation($element, $yamlform);
    $file_destination = $upload_location . '/' . $element['#yamlform_key'] . '.' . $file_extension;

    // Look for an existing temp files that have not been uploaded.
    $fids = \Drupal::entityQuery('file')
      ->condition('status', 0)
      ->condition('uid', \Drupal::currentUser()
      ->id())
      ->condition('uri', $upload_location . '/' . $element['#yamlform_key'] . '.%', 'LIKE')
      ->execute();
    if ($fids) {
      return reset($fids);
    }

    // Copy sample file or generate a new temp file that can be uploaded.
    $sample_file = drupal_get_path('module', 'yamlform') . '/tests/files/sample.' . $file_extension;
    if (file_exists($sample_file)) {
      $file_uri = file_unmanaged_copy($sample_file, $file_destination);
    }
    else {
      $file_uri = file_unmanaged_save_data('{empty}', $file_destination);
    }
    $file = File::create([
      'uri' => $file_uri,
      'uid' => \Drupal::currentUser()
        ->id(),
    ]);
    $file
      ->save();
    $fid = $file
      ->id();
    return $this
      ->hasMultipleValues($element) ? [
      $fid,
    ] : $fid;
  }

  /**
   * Get max file size for an element.
   *
   * @param array $element
   *   An element.
   *
   * @return int
   *   Max file size.
   */
  protected function getMaxFileSize(array $element) {

    // Set max file size.
    $max_filesize = \Drupal::config('yamlform.settings')
      ->get('file.default_max_filesize') ?: file_upload_max_size();
    $max_filesize = Bytes::toInt($max_filesize);
    if (!empty($element['#max_filesize'])) {
      $max_filesize = min($max_filesize, Bytes::toInt($element['#max_filesize']) * 1024 * 1024);
    }
    return $max_filesize;
  }

  /**
   * Get allowed file extensions for an element.
   *
   * @param array $element
   *   An element.
   *
   * @return int
   *   File extension.
   */
  protected function getFileExtensions(array $element = NULL) {
    $file_type = str_replace('yamlform_', '', $this
      ->getPluginId());

    // Set valid file extensions.
    $file_extensions = \Drupal::config('yamlform.settings')
      ->get("file.default_{$file_type}_extensions");
    if (!empty($element['#file_extensions'])) {
      $file_extensions = $element['#file_extensions'];
    }
    return $file_extensions;
  }

  /**
   * Get file upload location.
   *
   * @param array $element
   *   An element.
   * @param \Drupal\yamlform\YamlFormInterface $yamlform
   *   A form.
   *
   * @return string
   *   Upload location.
   */
  protected function getUploadLocation(array $element, YamlFormInterface $yamlform) {
    if (empty($element['#upload_location'])) {
      $upload_location = $this
        ->getUriScheme($element) . '://yamlform/' . $yamlform
        ->id() . '/_sid_';
    }
    else {
      $upload_location = $element['#upload_location'];
    }

    // Make sure the upload location exists and is writable.
    file_prepare_directory($upload_location, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
    return $upload_location;
  }

  /**
   * Get file upload URI scheme.
   *
   * Defaults to private file uploads.
   *
   * Drupal file upload by anonymous or untrusted users into public file systems
   * -- PSA-2016-003.
   *
   * @param array $element
   *   An element.
   *
   * @return string
   *   File upload URI scheme.
   *
   * @see https://www.drupal.org/psa-2016-003
   */
  protected function getUriScheme(array $element) {
    if (isset($element['#uri_scheme'])) {
      return $element['#uri_scheme'];
    }
    $scheme_options = self::getVisibleStreamWrappers();
    if (isset($scheme_options['private'])) {
      return 'private';
    }
    elseif (isset($scheme_options['public'])) {
      return 'public';
    }
    else {
      return 'private';
    }
  }

  /**
   * Form API callback. Consolidate the array of fids for this field into a single fids.
   */
  public static function validate(array &$element, FormStateInterface $form_state, &$complete_form) {

    // Call the default managed_element validation handler, which checks
    // the file entity and #required.
    // @see \Drupal\file\Element\ManagedFile::getInfo
    // @see \Drupal\yamlform\Plugin\YamlFormElement\ManagedFile::prepare
    ManagedFileElement::validateManagedFile($element, $form_state, $complete_form);
    if (!empty($element['#files'])) {
      $fids = array_keys($element['#files']);
      if (empty($element['#multiple'])) {
        $form_state
          ->setValueForElement($element, reset($fids));
      }
      else {
        $form_state
          ->setValueForElement($element, $fids);
      }
    }
    else {
      $form_state
        ->setValueForElement($element, NULL);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function form(array $form, FormStateInterface $form_state) {
    $form = parent::form($form, $form_state);
    $form['file'] = [
      '#type' => 'fieldset',
      '#title' => $this
        ->t('File settings'),
    ];
    $scheme_options = self::getVisibleStreamWrappers();
    $form['file']['uri_scheme'] = [
      '#type' => 'radios',
      '#title' => t('Upload destination'),
      '#description' => t('Select where the final files should be stored. Private file storage has more overhead than public files, but allows restricted access to files within this element.'),
      '#required' => TRUE,
      '#options' => $scheme_options,
    ];

    // Public files security warning.
    if (isset($scheme_options['public'])) {
      $form['file']['uri_public_warning'] = [
        '#type' => 'yamlform_message',
        '#message_type' => 'warning',
        '#message_message' => $this
          ->t('Public files upload destination is dangerous for forms that are available to anonymous and/or untrusted users.') . ' ' . $this
          ->t('For more information see: <a href="https://www.drupal.org/psa-2016-003">DRUPAL-PSA-2016-003</a>'),
        '#access' => TRUE,
        '#states' => [
          'visible' => [
            ':input[name="properties[uri_scheme]"]' => [
              'value' => 'public',
            ],
          ],
        ],
      ];
    }

    // Private files not set warning.
    if (!isset($scheme_options['private'])) {
      $form['file']['uri_private_warning'] = [
        '#type' => 'yamlform_message',
        '#message_type' => 'warning',
        '#message_message' => $this
          ->t('Private file system is not set. This must be changed in <a href="https://www.drupal.org/documentation/modules/file">settings.php</a>. For more information see: <a href="https://www.drupal.org/psa-2016-003">DRUPAL-PSA-2016-003</a>'),
        '#access' => TRUE,
      ];
    }
    $form['file']['max_filesize'] = [
      '#type' => 'number',
      '#title' => $this
        ->t('Maximum file size'),
      '#field_suffix' => $this
        ->t('MB'),
      '#description' => $this
        ->t('Enter the max file size a user may upload.'),
      '#min' => 1,
    ];
    $form['file']['file_extensions'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('File extensions'),
      '#description' => $this
        ->t('A list of additional file extensions for this upload field, separated by spaces.'),
      '#maxlength' => 255,
    ];
    $form['file']['multiple'] = [
      '#title' => $this
        ->t('Multiple'),
      '#type' => 'checkbox',
      '#return_value' => TRUE,
      '#description' => $this
        ->t('Check this option if the user should be allowed to upload multiple files.'),
    ];
    return $form;
  }

  /**
   * Control access to form submission private file downloads.
   *
   * @param string $uri
   *   The URI of the file.
   *
   * @return mixed
   *   Returns NULL is the file is not attached to a form submission.
   *   Returns -1 if the user does not have permission to access a form.
   *   Returns an associative array of headers.
   *
   * @see hook_file_download()
   * @see yamlform_file_download()
   */
  public static function accessFileDownload($uri) {
    $files = \Drupal::entityTypeManager()
      ->getStorage('file')
      ->loadByProperties([
      'uri' => $uri,
    ]);
    if (empty($files)) {
      return NULL;
    }
    $file = reset($files);
    if (empty($file)) {
      return NULL;
    }

    /** @var \Drupal\file\FileUsage\FileUsageInterface $file_usage */
    $file_usage = \Drupal::service('file.usage');
    $usage = $file_usage
      ->listUsage($file);
    foreach ($usage as $module => $entity_types) {

      // Check for YAML Form module.
      if ($module != 'yamlform') {
        continue;
      }
      foreach ($entity_types as $entity_type => $counts) {
        $entity_ids = array_keys($counts);

        // Check for form submission entity type.
        if ($entity_type != 'yamlform_submission' || empty($entity_ids)) {
          continue;
        }

        // Get form submission.
        $yamlform_submission = YamlFormSubmission::load(reset($entity_ids));
        if (!$yamlform_submission) {
          continue;
        }

        // Check form submission view access.
        if (!$yamlform_submission
          ->access('view')) {
          return -1;
        }

        // Return file content headers.
        return file_get_content_headers($file);
      }
    }
    return NULL;
  }

  /**
   * Get visible stream wrappers.
   *
   * @return array
   *   An associative array of visible stream wrappers keyed by type.
   */
  public static function getVisibleStreamWrappers() {
    $stream_wrappers = \Drupal::service('stream_wrapper_manager')
      ->getNames(StreamWrapperInterface::WRITE_VISIBLE);
    if (!\Drupal::config('yamlform.settings')
      ->get('file.file_public')) {
      unset($stream_wrappers['public']);
    }
    return $stream_wrappers;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
YamlFormElementBase::$configFactory protected property The configuration factory.
YamlFormElementBase::$currentUser protected property The current user.
YamlFormElementBase::$elementInfo protected property A element info manager.
YamlFormElementBase::$elementManager protected property The form element manager.
YamlFormElementBase::$entityTypeManager protected property The entity type manager.
YamlFormElementBase::$logger protected property A logger instance.
YamlFormElementBase::$tokenManager protected property The token manager.
YamlFormElementBase::build protected function Build an element as text or HTML. 2
YamlFormElementBase::buildConfigurationForm public function Form constructor. Overrides PluginFormInterface::buildConfigurationForm 1
YamlFormElementBase::buildExportHeader public function Build an element's export header. Overrides YamlFormElementInterface::buildExportHeader 3
YamlFormElementBase::buildExportOptionsForm public function Get an element's export options form. Overrides YamlFormElementInterface::buildExportOptionsForm 4
YamlFormElementBase::buildExportRecord public function Build an element's export row. Overrides YamlFormElementInterface::buildExportRecord 5
YamlFormElementBase::buildHtml public function Build an element as HTML element. Overrides YamlFormElementInterface::buildHtml 1
YamlFormElementBase::buildText public function Build an element as text element. Overrides YamlFormElementInterface::buildText 1
YamlFormElementBase::checkAccessRules public function Check element access (rules). Overrides YamlFormElementInterface::checkAccessRules
YamlFormElementBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
YamlFormElementBase::formatTableColumn public function Format an element's table column value. Overrides YamlFormElementInterface::formatTableColumn 2
YamlFormElementBase::getAdminLabel public function Get an element's admin label (#admin_title, #title or #yamlform_key). Overrides YamlFormElementInterface::getAdminLabel
YamlFormElementBase::getConfigurationFormProperties public function Get an associative array of element properties from configuration form. Overrides YamlFormElementInterface::getConfigurationFormProperties 2
YamlFormElementBase::getConfigurationFormProperty protected function Get configuration property value. 1
YamlFormElementBase::getDefaultBaseProperties protected function Get default base properties used by all elements.
YamlFormElementBase::getElementSelectorInputsOptions protected function Get an element's (sub)inputs selectors as options. 7
YamlFormElementBase::getElementStateOptions public function Get an element's supported states as options. Overrides YamlFormElementInterface::getElementStateOptions
YamlFormElementBase::getExportDefaultOptions public function Get an element's default export options. Overrides YamlFormElementInterface::getExportDefaultOptions 4
YamlFormElementBase::getFormat public function Get element's format name by looking for '#format' property, global settings, and finally default settings. Overrides YamlFormElementInterface::getFormat 1
YamlFormElementBase::getInfo public function Retrieves the default properties for the defined element type. Overrides YamlFormElementInterface::getInfo
YamlFormElementBase::getKey public function Get an element's key/name. Overrides YamlFormElementInterface::getKey
YamlFormElementBase::getLabel public function Get an element's label (#title or #yamlform_key). Overrides YamlFormElementInterface::getLabel
YamlFormElementBase::getPluginApiLink public function Get link to element's API documentation. Overrides YamlFormElementInterface::getPluginApiLink
YamlFormElementBase::getPluginApiUrl public function Get the URL for the element's API documentation. Overrides YamlFormElementInterface::getPluginApiUrl
YamlFormElementBase::getPluginLabel public function Gets the label of the plugin instance. Overrides YamlFormElementInterface::getPluginLabel
YamlFormElementBase::getRelatedTypes public function Get related element types. Overrides YamlFormElementInterface::getRelatedTypes 3
YamlFormElementBase::getTableColumn public function Get element's table column(s) settings. Overrides YamlFormElementInterface::getTableColumn 3
YamlFormElementBase::getTranslatableProperties public function Get translatable properties. Overrides YamlFormElementInterface::getTranslatableProperties 7
YamlFormElementBase::getTypeName public function Gets the type name (aka id) of the plugin instance with the 'yamlform_' prefix. Overrides YamlFormElementInterface::getTypeName
YamlFormElementBase::hasProperty public function Determine if an element supports a specified property. Overrides YamlFormElementInterface::hasProperty
YamlFormElementBase::hasWrapper public function Checks if the element has a wrapper. Overrides YamlFormElementInterface::hasWrapper
YamlFormElementBase::initialize public function Initialize an element to be displayed, rendered, or exported. Overrides YamlFormElementInterface::initialize 1
YamlFormElementBase::isComposite public function Checks if element is a composite element. Overrides YamlFormElementInterface::isComposite
YamlFormElementBase::isContainer public function Checks if element is a container that can contain elements. Overrides YamlFormElementInterface::isContainer 3
YamlFormElementBase::isDisabled public function Checks if element is disabled. Overrides YamlFormElementInterface::isDisabled
YamlFormElementBase::isHidden public function Checks if element is hidden. Overrides YamlFormElementInterface::isHidden
YamlFormElementBase::isInput public function Checks if the element carries a value. Overrides YamlFormElementInterface::isInput 5
YamlFormElementBase::isRoot public function Checks if element is a root element. Overrides YamlFormElementInterface::isRoot 1
YamlFormElementBase::postCreate public function Acts on a form submission element after it is created. Overrides YamlFormElementInterface::postCreate 1
YamlFormElementBase::postLoad public function Acts on loaded form submission. Overrides YamlFormElementInterface::postLoad 1
YamlFormElementBase::preCreate public function Changes the values of an entity before it is created. Overrides YamlFormElementInterface::preCreate 1
YamlFormElementBase::preDelete public function 1
YamlFormElementBase::prefixExportHeader protected function Prefix an element's export header.
YamlFormElementBase::preSave public function Acts on a form submission element before the presave hook is invoked. Overrides YamlFormElementInterface::preSave 2
YamlFormElementBase::setConfigurationFormDefaultValue protected function Set an element's configuration form element default value. 2
YamlFormElementBase::setConfigurationFormDefaultValueRecursive protected function Set configuration form default values recursively.
YamlFormElementBase::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm
YamlFormElementBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm 3
YamlFormElementBase::validateUnique public static function Form API callback. Validate #unique value.
YamlFormElementBase::__construct public function Constructs a Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct
YamlFormManagedFileBase::accessFileDownload public static function Control access to form submission private file downloads.
YamlFormManagedFileBase::displayDisabledWarning public function Display element disabled warning. Overrides YamlFormElementBase::displayDisabledWarning
YamlFormManagedFileBase::form public function Gets the actual configuration form array to be built. Overrides YamlFormElementBase::form
YamlFormManagedFileBase::formatHtml public function Format an element's value as HTML. Overrides YamlFormElementBase::formatHtml
YamlFormManagedFileBase::formatItems protected function Format a managed files as array of strings.
YamlFormManagedFileBase::formatText public function Format an element's value as plain text. Overrides YamlFormElementBase::formatText
YamlFormManagedFileBase::getDefaultFormat public function Get an element's default format name. Overrides YamlFormElementBase::getDefaultFormat
YamlFormManagedFileBase::getDefaultProperties public function Only a few elements don't inherit these default properties. Overrides YamlFormElementBase::getDefaultProperties
YamlFormManagedFileBase::getElementSelectorOptions public function Get an element's selectors as options. Overrides YamlFormElementBase::getElementSelectorOptions
YamlFormManagedFileBase::getFileExtensions protected function Get allowed file extensions for an element.
YamlFormManagedFileBase::getFormats public function Get an element's available formats. Overrides YamlFormElementBase::getFormats 3
YamlFormManagedFileBase::getMaxFileSize protected function Get max file size for an element.
YamlFormManagedFileBase::getTestValue public function Get test value for an element. Overrides YamlFormElementBase::getTestValue
YamlFormManagedFileBase::getUploadLocation protected function Get file upload location.
YamlFormManagedFileBase::getUriScheme protected function Get file upload URI scheme.
YamlFormManagedFileBase::getVisibleStreamWrappers public static function Get visible stream wrappers.
YamlFormManagedFileBase::hasMultipleValues public function Checks if element value has multiple values. Overrides YamlFormElementBase::hasMultipleValues
YamlFormManagedFileBase::isEnabled public function Checks if element is enabled. Overrides YamlFormElementBase::isEnabled
YamlFormManagedFileBase::isMultiline public function Checks if element value could contain multiple lines. Overrides YamlFormElementBase::isMultiline
YamlFormManagedFileBase::postDelete public function Delete any additional value associated with an element. Overrides YamlFormElementBase::postDelete
YamlFormManagedFileBase::postSave public function Acts on a saved form submission element before the insert or update hook is invoked. Overrides YamlFormElementBase::postSave
YamlFormManagedFileBase::prepare public function Prepare an element to be rendered within a form. Overrides YamlFormElementBase::prepare
YamlFormManagedFileBase::prepareWrapper protected function Set an elements Flexbox and #states wrapper. Overrides YamlFormElementBase::prepareWrapper
YamlFormManagedFileBase::setDefaultValue public function Set an element's default value using saved data. Overrides YamlFormElementBase::setDefaultValue
YamlFormManagedFileBase::validate public static function Form API callback. Consolidate the array of fids for this field into a single fids.