You are here

class YamlFormSubmissionStorage in YAML Form 8

Defines the form submission storage.

Hierarchy

Expanded class hierarchy of YamlFormSubmissionStorage

File

src/YamlFormSubmissionStorage.php, line 14

Namespace

Drupal\yamlform
View source
class YamlFormSubmissionStorage extends SqlContentEntityStorage implements YamlFormSubmissionStorageInterface {

  /**
   * Array used to element data schema.
   *
   * @var array
   */
  protected $elementDataSchema = [];

  /**
   * {@inheritdoc}
   */
  public function getFieldDefinitions() {

    /** @var \Drupal\Core\Field\BaseFieldDefinition[] $definitions */
    $field_definitions = $this->entityManager
      ->getBaseFieldDefinitions('yamlform_submission');

    // For now never let any see or export the serialize YAML data field.
    unset($field_definitions['data']);
    $definitions = [];
    foreach ($field_definitions as $field_name => $field_definition) {
      $definitions[$field_name] = [
        'title' => $field_definition
          ->getLabel(),
        'name' => $field_name,
        'type' => $field_definition
          ->getType(),
        'target_type' => $field_definition
          ->getSetting('target_type'),
      ];
    }
    return $definitions;
  }

  /**
   * {@inheritdoc}
   */
  public function loadDraft(YamlFormInterface $yamlform, EntityInterface $source_entity = NULL, AccountInterface $account = NULL) {
    $query = $this
      ->getQuery();
    $query
      ->condition('in_draft', TRUE);
    $query
      ->condition('yamlform_id', $yamlform
      ->id());
    $query
      ->condition('uid', $account
      ->id());
    if ($source_entity) {
      $query
        ->condition('entity_type', $source_entity
        ->getEntityTypeId());
      $query
        ->condition('entity_id', $source_entity
        ->id());
    }
    else {
      $query
        ->notExists('entity_type');
      $query
        ->notExists('entity_id');
    }
    if ($entity_ids = $query
      ->execute()) {
      return $this
        ->load(reset($entity_ids));
    }
    else {
      return NULL;
    }
  }

  /**
   * {@inheritdoc}
   */
  protected function doCreate(array $values) {

    /** @var \Drupal\yamlform\YamlFormSubmissionInterface $entity */
    $entity = parent::doCreate($values);
    if (!empty($values['data'])) {
      $data = is_array($values['data']) ? $values['data'] : Yaml::decode($values['data']);
      $entity
        ->setData($data);
    }
    return $entity;
  }

  /**
   * {@inheritdoc}
   */
  public function loadMultiple(array $ids = NULL) {

    /** @var \Drupal\yamlform\YamlFormSubmissionInterface[] $yamlform_submissions */
    $yamlform_submissions = parent::loadMultiple($ids);
    $this
      ->loadData($yamlform_submissions);
    return $yamlform_submissions;
  }

  /**
   * {@inheritdoc}
   */
  public function deleteAll(YamlFormInterface $yamlform = NULL, EntityInterface $source_entity = NULL, $limit = NULL, $max_sid = NULL) {
    $query = $this
      ->getQuery()
      ->sort('sid');
    if ($yamlform) {
      $query
        ->condition('yamlform_id', $yamlform
        ->id());
    }
    if ($source_entity) {
      $query
        ->condition('entity_type', $source_entity
        ->getEntityTypeId());
      $query
        ->condition('entity_id', $source_entity
        ->id());
    }
    if ($limit) {
      $query
        ->range(0, $limit);
    }
    if ($max_sid) {
      $query
        ->condition('sid', $max_sid, '<=');
    }
    $entity_ids = $query
      ->execute();
    $entities = $this
      ->loadMultiple($entity_ids);
    $this
      ->delete($entities);
    return count($entities);
  }

  /**
   * {@inheritdoc}
   */
  public function getTotal(YamlFormInterface $yamlform = NULL, EntityInterface $source_entity = NULL, AccountInterface $account = NULL) {
    $query = $this
      ->getQuery();
    $query
      ->condition('in_draft', FALSE);
    if ($yamlform) {
      $query
        ->condition('yamlform_id', $yamlform
        ->id());
    }
    if ($source_entity) {
      $query
        ->condition('entity_type', $source_entity
        ->getEntityTypeId());
      $query
        ->condition('entity_id', $source_entity
        ->id());
    }
    if ($account) {
      $query
        ->condition('uid', $account
        ->id());
    }

    // Issue: Query count method is not working for SQL Lite.
    // return $query->count()->execute();
    // Work-around: Manually count the number of entity ids.
    return count($query
      ->execute());
  }

  /**
   * {@inheritdoc}
   */
  public function getMaxSubmissionId(YamlFormInterface $yamlform = NULL, EntityInterface $source_entity = NULL, AccountInterface $account = NULL) {
    $query = $this
      ->getQuery();
    $query
      ->sort('sid', 'DESC');
    if ($yamlform) {
      $query
        ->condition('yamlform_id', $yamlform
        ->id());
    }
    if ($source_entity) {
      $query
        ->condition('entity_type', $source_entity
        ->getEntityTypeId());
      $query
        ->condition('entity_id', $source_entity
        ->id());
    }
    if ($account) {
      $query
        ->condition('uid', $account
        ->id());
    }
    $query
      ->range(0, 1);
    $result = $query
      ->execute();
    return reset($result);
  }

  /****************************************************************************/

  // Paging methods.

  /****************************************************************************/

  /**
   * {@inheritdoc}
   */
  public function getFirstSubmission(YamlFormInterface $yamlform, EntityInterface $source_entity = NULL, AccountInterface $account = NULL) {
    return $this
      ->getTerminusSubmission($yamlform, $source_entity, $account, 'ASC');
  }

  /**
   * {@inheritdoc}
   */
  public function getLastSubmission(YamlFormInterface $yamlform, EntityInterface $source_entity = NULL, AccountInterface $account = NULL) {
    return $this
      ->getTerminusSubmission($yamlform, $source_entity, $account, 'DESC');
  }

  /**
   * {@inheritdoc}
   */
  public function getPreviousSubmission(YamlFormSubmissionInterface $yamlform_submission, EntityInterface $source_entity = NULL, AccountInterface $account = NULL) {
    return $this
      ->getSiblingSubmission($yamlform_submission, $source_entity, $account, 'previous');
  }

  /**
   * {@inheritdoc}
   */
  public function getNextSubmission(YamlFormSubmissionInterface $yamlform_submission, EntityInterface $source_entity = NULL, AccountInterface $account = NULL) {
    return $this
      ->getSiblingSubmission($yamlform_submission, $source_entity, $account, 'next');
  }

  /**
   * {@inheritdoc}
   */
  public function getSourceEntityTypes(YamlFormInterface $yamlform) {
    $entity_types = Database::getConnection()
      ->select('yamlform_submission', 's')
      ->distinct()
      ->fields('s', [
      'entity_type',
    ])
      ->condition('s.yamlform_id', $yamlform
      ->id())
      ->condition('s.entity_type', 'yamlform', '<>')
      ->orderBy('s.entity_type', 'ASC')
      ->execute()
      ->fetchCol();
    $entity_type_labels = \Drupal::service('entity_type.repository')
      ->getEntityTypeLabels();
    ksort($entity_type_labels);
    return array_intersect_key($entity_type_labels, array_flip($entity_types));
  }

  /**
   * {@inheritdoc}
   */
  protected function getTerminusSubmission(YamlFormInterface $yamlform, EntityInterface $source_entity = NULL, AccountInterface $account = NULL, $sort = 'DESC') {
    $query = $this
      ->getQuery();
    $query
      ->condition('yamlform_id', $yamlform
      ->id());
    $query
      ->condition('in_draft', FALSE);
    $query
      ->range(0, 1);
    if ($source_entity) {
      $query
        ->condition('entity_type', $source_entity
        ->getEntityTypeId());
      $query
        ->condition('entity_id', $source_entity
        ->id());
    }
    if ($account) {
      $query
        ->condition('uid', $account
        ->id());
    }
    $query
      ->sort('sid', $sort);
    return ($entity_ids = $query
      ->execute()) ? $this
      ->load(reset($entity_ids)) : NULL;
  }

  /**
   * {@inheritdoc}
   */
  protected function getSiblingSubmission(YamlFormSubmissionInterface $yamlform_submission, EntityInterface $entity = NULL, AccountInterface $account = NULL, $direction = 'previous') {
    $yamlform = $yamlform_submission
      ->getYamlForm();
    $query = $this
      ->getQuery();
    $query
      ->condition('yamlform_id', $yamlform
      ->id());
    $query
      ->range(0, 1);
    if ($entity) {
      $query
        ->condition('entity_type', $entity
        ->getEntityTypeId());
      $query
        ->condition('entity_id', $entity
        ->id());
    }
    if ($account) {
      $query
        ->condition('uid', $account
        ->id());
    }
    if ($direction == 'previous') {
      $query
        ->condition('sid', $yamlform_submission
        ->id(), '<');
      $query
        ->sort('sid', 'DESC');
    }
    else {
      $query
        ->condition('sid', $yamlform_submission
        ->id(), '>');
      $query
        ->sort('sid', 'ASC');
    }
    return ($entity_ids = $query
      ->execute()) ? $this
      ->load(reset($entity_ids)) : NULL;
  }

  /****************************************************************************/

  // YamlFormSubmissionEntityList methods.

  /****************************************************************************/

  /**
   * {@inheritdoc}
   */
  public function getCustomColumns(YamlFormInterface $yamlform = NULL, EntityInterface $source_entity = NULL, AccountInterface $account = NULL, $include_elements = TRUE) {

    // Get custom columns from the form's state.
    if ($source_entity) {
      $source_key = $source_entity
        ->getEntityTypeId() . '.' . $source_entity
        ->id();
      $custom_column_names = $yamlform
        ->getState("results.custom.columns.{$source_key}", []);

      // If the source entity does not have custom columns, then see if we
      // can use the main form as the default custom columns.
      if (empty($custom_column_names) && $yamlform
        ->getState("results.custom.default", FALSE)) {
        $custom_column_names = $yamlform
          ->getState('results.custom.columns', []);
      }
    }
    else {
      $custom_column_names = $yamlform
        ->getState('results.custom.columns', []);
    }
    if (empty($custom_column_names)) {
      return $this
        ->getDefaultColumns($yamlform, $source_entity, $account, $include_elements);
    }

    // Get custom column with labels.
    $columns = $this
      ->getColumns($yamlform, $source_entity, $account, $include_elements);
    $custom_columns = [];
    foreach ($custom_column_names as $column_name) {
      if (isset($columns[$column_name])) {
        $custom_columns[$column_name] = $columns[$column_name];
      }
    }
    return $custom_columns;
  }

  /**
   * {@inheritdoc}
   */
  public function getDefaultColumns(YamlFormInterface $yamlform = NULL, EntityInterface $source_entity = NULL, AccountInterface $account = NULL, $include_elements = TRUE) {
    $columns = $this
      ->getColumns($yamlform, $source_entity, $account, $include_elements);

    // Hide certain unnecessary columns, that have default set to FALSE.
    foreach ($columns as $column_name => $column) {
      if (isset($column['default']) && $column['default'] === FALSE) {
        unset($columns[$column_name]);
      }
    }
    return $columns;
  }

  /**
   * {@inheritdoc}
   */
  public function getColumns(YamlFormInterface $yamlform = NULL, EntityInterface $source_entity = NULL, AccountInterface $account = NULL, $include_elements = TRUE) {
    $view_any = $yamlform && $yamlform
      ->access('submission_view_any') ? TRUE : FALSE;
    $columns = [];

    // Serial number.
    $columns['serial'] = [
      'title' => $this
        ->t('#'),
    ];

    // Submission ID.
    $columns['sid'] = [
      'title' => $this
        ->t('SID'),
    ];

    // UUID.
    $columns['uuid'] = [
      'title' => $this
        ->t('UUID'),
      'default' => FALSE,
    ];

    // Sticky (Starred/Unstarred).
    if (empty($account)) {
      $columns['sticky'] = [
        'title' => $this
          ->t('Starred'),
      ];

      // Notes.
      $columns['notes'] = [
        'title' => $this
          ->t('Notes'),
      ];
    }

    // Created.
    $columns['created'] = [
      'title' => $this
        ->t('Created'),
    ];

    // Completed.
    $columns['completed'] = [
      'title' => $this
        ->t('Completed'),
      'default' => FALSE,
    ];

    // Changed.
    $columns['changed'] = [
      'title' => $this
        ->t('Changed'),
      'default' => FALSE,
    ];

    // Source entity.
    if ($view_any && empty($source_entity)) {
      $columns['entity'] = [
        'title' => $this
          ->t('Submitted to'),
        'sort' => FALSE,
      ];
    }

    // Submitted by.
    if (empty($account)) {
      $columns['uid'] = [
        'title' => $this
          ->t('User'),
      ];
    }

    // Submission language.
    if ($view_any && \Drupal::moduleHandler()
      ->moduleExists('language')) {
      $columns['langcode'] = [
        'title' => $this
          ->t('Language'),
      ];
    }

    // Remote address.
    $columns['remote_addr'] = [
      'title' => $this
        ->t('IP address'),
    ];

    // Form.
    if (empty($yamlform) && empty($source_entity)) {
      $columns['yamlform_id'] = [
        'title' => $this
          ->t('Form'),
      ];
    }

    // Form elements.
    if ($yamlform && $include_elements) {

      /** @var \Drupal\yamlform\YamlFormElementManagerInterface $element_manager */
      $element_manager = \Drupal::service('plugin.manager.yamlform.element');
      $elements = $yamlform
        ->getElementsFlattenedAndHasValue();
      foreach ($elements as $element) {

        /** @var \Drupal\yamlform\YamlFormElementInterface $element_handler */
        $element_handler = $element_manager
          ->createInstance($element['#type']);
        $columns += $element_handler
          ->getTableColumn($element);
      }
    }

    // Operations.
    if (empty($account)) {
      $columns['operations'] = [
        'title' => $this
          ->t('Operations'),
        'sort' => FALSE,
      ];
    }

    // Add name and format to all columns.
    foreach ($columns as $name => &$column) {
      $column['name'] = $name;
      $column['format'] = 'value';
    }
    return $columns;
  }

  /**
   * {@inheritdoc}
   */
  public function getCustomSetting($name, $default, YamlFormInterface $yamlform = NULL, EntityInterface $source_entity = NULL) {

    // Return the default value is form and source entity is not defined.
    if (!$yamlform && !$source_entity) {
      return $default;
    }
    $key = "results.custom.{$name}";
    if (!$source_entity) {
      return $yamlform
        ->getState($key, $default);
    }
    $source_key = $source_entity
      ->getEntityTypeId() . '.' . $source_entity
      ->id();
    if ($yamlform
      ->hasState("{$key}.{$source_key}")) {
      return $yamlform
        ->getState("{$key}.{$source_key}", $default);
    }
    if ($yamlform
      ->getState("results.custom.default", FALSE)) {
      return $yamlform
        ->getState($key, $default);
    }
    else {
      return $default;
    }
  }

  /****************************************************************************/

  // Invoke YamlFormElement and YamlFormHandler plugin methods.

  /****************************************************************************/

  /**
   * {@inheritdoc}
   */
  public function create(array $values = []) {

    /** @var \Drupal\yamlform\YamlFormSubmissionInterface $entity */

    // Pre create is called via the YamlFormSubmission entity.
    // @see: \Drupal\yamlform\Entity\YamlFormSubmission::preCreate
    $entity = parent::create($values);
    $this
      ->invokeYamlFormElements('postCreate', $entity);
    $this
      ->invokeYamlFormHandlers('postCreate', $entity);
    return $entity;
  }

  /**
   * {@inheritdoc}
   */
  protected function postLoad(array &$entities) {

    /** @var \Drupal\yamlform\YamlFormSubmissionInterface $entity */
    $return = parent::postLoad($entities);
    foreach ($entities as $entity) {
      $this
        ->invokeYamlFormElements('postLoad', $entity);
      $this
        ->invokeYamlFormHandlers('postLoad', $entity);
    }
    return $return;
  }

  /**
   * {@inheritdoc}
   */
  protected function doPreSave(EntityInterface $entity) {

    /** @var \Drupal\yamlform\YamlFormSubmissionInterface $entity */
    $id = parent::doPreSave($entity);
    $this
      ->invokeYamlFormElements('preSave', $entity);
    $this
      ->invokeYamlFormHandlers('preSave', $entity);
    return $id;
  }

  /**
   * {@inheritdoc}
   */
  protected function doSave($id, EntityInterface $entity) {

    /** @var \Drupal\yamlform\YamlFormSubmissionInterface $entity */
    if ($entity
      ->getYamlForm()
      ->getSetting('results_disabled')) {
      return YamlFormSubmissionStorageInterface::SAVED_DISABLED;
    }
    $is_new = $entity
      ->isNew();
    if (!$entity
      ->serial()) {
      $entity
        ->set('serial', $this
        ->getNextSerial($entity));
    }
    $result = parent::doSave($id, $entity);

    // Save data.
    $this
      ->saveData($entity, !$is_new);

    // DEBUG: dsm($entity->getState());
    // Log transaction.
    $yamlform = $entity
      ->getYamlForm();
    $context = [
      '@id' => $entity
        ->id(),
      '@form' => $yamlform
        ->label(),
      'link' => $entity
        ->toLink(t('Edit'), 'edit-form')
        ->toString(),
    ];
    switch ($entity
      ->getState()) {
      case YamlFormSubmissionInterface::STATE_DRAFT:
        \Drupal::logger('yamlform')
          ->notice('@form: Submission #@id draft saved.', $context);
        break;
      case YamlFormSubmissionInterface::STATE_UPDATED:
        \Drupal::logger('yamlform')
          ->notice('@form: Submission #@id updated.', $context);
        break;
      case YamlFormSubmissionInterface::STATE_COMPLETED:
        if ($result === SAVED_NEW) {
          \Drupal::logger('yamlform')
            ->notice('@form: Submission #@id created.', $context);
        }
        else {
          \Drupal::logger('yamlform')
            ->notice('@form: Submission #@id completed.', $context);
        }
        break;
    }
    return $result;
  }

  /**
   * Returns the next serial number.
   *
   * @return int
   *   The next serial number.
   */
  protected function getNextSerial(YamlFormSubmissionInterface $yamlform_submission) {
    $yamlform = $yamlform_submission
      ->getYamlForm();
    $next_serial = $yamlform
      ->getState('next_serial');
    $max_serial = $this
      ->getMaxSerial($yamlform);
    $serial = max($next_serial, $max_serial);
    $yamlform
      ->setState('next_serial', $serial + 1);
    return $serial;
  }

  /**
   * {@inheritdoc}
   */
  public function getMaxSerial(YamlFormInterface $yamlform) {
    $query = db_select('yamlform_submission');
    $query
      ->condition('yamlform_id', $yamlform
      ->id());
    $query
      ->addExpression('MAX(serial)');
    return $query
      ->execute()
      ->fetchField() + 1;
  }

  /**
   * {@inheritdoc}
   */
  protected function doPostSave(EntityInterface $entity, $update) {

    /** @var \Drupal\yamlform\YamlFormSubmissionInterface $entity */
    parent::doPostSave($entity, $update);
    $this
      ->invokeYamlFormElements('postSave', $entity, $update);
    $this
      ->invokeYamlFormHandlers('postSave', $entity, $update);
  }

  /**
   * {@inheritdoc}
   */
  public function delete(array $entities) {

    /** @var \Drupal\yamlform\YamlFormSubmissionInterface $entity */
    if (!$entities) {

      // If no entities were passed, do nothing.
      return;
    }
    foreach ($entities as $entity) {
      $this
        ->invokeYamlFormElements('preDelete', $entity);
      $this
        ->invokeYamlFormHandlers('preDelete', $entity);
    }
    $return = parent::delete($entities);
    $this
      ->deleteData($entities);
    foreach ($entities as $entity) {
      $this
        ->invokeYamlFormElements('postDelete', $entity);
      $this
        ->invokeYamlFormHandlers('postDelete', $entity);
    }

    // Log deleted.
    foreach ($entities as $entity) {
      \Drupal::logger('yamlform')
        ->notice('Deleted @form: Submission #@id.', [
        '@id' => $entity
          ->id(),
        '@form' => $entity
          ->getYamlForm()
          ->label(),
      ]);
    }
    return $return;
  }

  /**
   * {@inheritdoc}
   */
  public function invokeYamlFormHandlers($method, YamlFormSubmissionInterface $yamlform_submission, &$context1 = NULL, &$context2 = NULL) {
    $yamlform = $yamlform_submission
      ->getYamlForm();
    $yamlform
      ->invokeHandlers($method, $yamlform_submission, $context1, $context2);
  }

  /**
   * {@inheritdoc}
   */
  public function invokeYamlFormElements($method, YamlFormSubmissionInterface $yamlform_submission, &$context1 = NULL, &$context2 = NULL) {
    $yamlform = $yamlform_submission
      ->getYamlForm();
    $yamlform
      ->invokeElements($method, $yamlform_submission, $context1, $context2);
  }

  /****************************************************************************/

  // Data handlers.

  /****************************************************************************/

  /**
   * Save form submission data from the 'yamlform_submission_data' table.
   *
   * @param array $yamlform_submissions
   *   An array of form submissions.
   */
  protected function loadData(array &$yamlform_submissions) {

    // Load form submission data.
    if ($sids = array_keys($yamlform_submissions)) {
      $result = Database::getConnection()
        ->select('yamlform_submission_data', 'sd')
        ->fields('sd', [
        'yamlform_id',
        'sid',
        'name',
        'property',
        'delta',
        'value',
      ])
        ->condition('sd.sid', $sids, 'IN')
        ->orderBy('sd.sid', 'ASC')
        ->orderBy('sd.name', 'ASC')
        ->orderBy('sd.property', 'ASC')
        ->orderBy('sd.delta', 'ASC')
        ->execute();
      $submissions_data = [];
      while ($record = $result
        ->fetchAssoc()) {
        $sid = $record['sid'];
        $name = $record['name'];
        $elements = $yamlform_submissions[$sid]
          ->getYamlForm()
          ->getElementsFlattenedAndHasValue();
        $element = isset($elements[$name]) ? $elements[$name] : [
          '#yamlform_multiple' => FALSE,
          '#yamlform_composite' => FALSE,
        ];
        if ($element['#yamlform_multiple']) {
          $submissions_data[$sid][$name][$record['delta']] = $record['value'];
        }
        elseif ($element['#yamlform_composite']) {
          $submissions_data[$sid][$name][$record['property']] = $record['value'];
        }
        else {
          $submissions_data[$sid][$name] = $record['value'];
        }
      }

      // Set form submission data via setData().
      foreach ($submissions_data as $sid => $submission_data) {
        $yamlform_submissions[$sid]
          ->setData($submission_data);
        $yamlform_submissions[$sid]
          ->setOriginalData($submission_data);
      }
    }
  }

  /**
   * Save form submission data to the 'yamlform_submission_data' table.
   *
   * @param \Drupal\yamlform\YamlFormSubmissionInterface $yamlform_submission
   *   A form submission.
   * @param bool $delete_first
   *   TRUE to delete any data first. For new submissions this is not needed.
   */
  protected function saveData(YamlFormSubmissionInterface $yamlform_submission, $delete_first = TRUE) {

    // Get submission data rows.
    $data = $yamlform_submission
      ->getData();
    $yamlform_id = $yamlform_submission
      ->getYamlForm()
      ->id();
    $sid = $yamlform_submission
      ->id();
    $elements = $yamlform_submission
      ->getYamlForm()
      ->getElementsFlattenedAndHasValue();
    $rows = [];
    foreach ($data as $name => $item) {
      $element = isset($elements[$name]) ? $elements[$name] : [
        '#yamlform_multiple' => FALSE,
        '#yamlform_composite' => FALSE,
      ];
      if ($element['#yamlform_multiple']) {
        if (is_array($item)) {
          foreach ($item as $delta => $value) {
            $rows[] = [
              'yamlform_id' => $yamlform_id,
              'sid' => $sid,
              'name' => $name,
              'property' => '',
              'delta' => $delta,
              'value' => (string) $value,
            ];
          }
        }
      }
      elseif ($element['#yamlform_composite']) {
        if (is_array($item)) {
          foreach ($item as $property => $value) {
            $rows[] = [
              'yamlform_id' => $yamlform_id,
              'sid' => $sid,
              'name' => $name,
              'property' => $property,
              'delta' => 0,
              'value' => (string) $value,
            ];
          }
        }
      }
      else {
        $rows[] = [
          'yamlform_id' => $yamlform_id,
          'sid' => $sid,
          'name' => $name,
          'property' => '',
          'delta' => 0,
          'value' => (string) $item,
        ];
      }
    }
    if ($delete_first) {

      // Delete existing submission data rows.
      $this->database
        ->delete('yamlform_submission_data')
        ->condition('sid', $sid)
        ->execute();
    }

    // Insert new submission data rows.
    $query = $this->database
      ->insert('yamlform_submission_data')
      ->fields([
      'yamlform_id',
      'sid',
      'name',
      'property',
      'delta',
      'value',
    ]);
    foreach ($rows as $row) {
      $query
        ->values($row);
    }
    $query
      ->execute();
  }

  /**
   * Delete form submission data fromthe 'yamlform_submission_data' table.
   *
   * @param array $yamlform_submissions
   *   An array of form submissions.
   */
  protected function deleteData(array $yamlform_submissions) {
    Database::getConnection()
      ->delete('yamlform_submission_data')
      ->condition('sid', array_keys($yamlform_submissions), 'IN')
      ->execute();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContentEntityStorageBase::$bundleKey protected property The entity bundle key.
ContentEntityStorageBase::$cacheBackend protected property Cache backend.
ContentEntityStorageBase::$deprecatedProperties protected property
ContentEntityStorageBase::$entityFieldManager protected property The entity field manager service.
ContentEntityStorageBase::$entityTypeBundleInfo protected property The entity bundle info.
ContentEntityStorageBase::$latestRevisionIds protected property Stores the latest revision IDs for entities.
ContentEntityStorageBase::cleanIds protected function Ensures integer entity key values are valid.
ContentEntityStorageBase::createRevision public function Creates a new revision starting off from the specified entity object. Overrides TranslatableRevisionableStorageInterface::createRevision
ContentEntityStorageBase::createTranslation public function Constructs a new entity translation object, without permanently saving it. Overrides TranslatableStorageInterface::createTranslation
ContentEntityStorageBase::createWithSampleValues public function Creates an entity with sample field values. Overrides ContentEntityStorageInterface::createWithSampleValues 1
ContentEntityStorageBase::deleteRevision public function Delete a specific entity revision. Overrides EntityStorageInterface::deleteRevision 1
ContentEntityStorageBase::doDelete protected function Performs storage-specific entity deletion. Overrides EntityStorageBase::doDelete 1
ContentEntityStorageBase::getFromPersistentCache protected function Gets entities from the persistent cache backend.
ContentEntityStorageBase::getLatestRevisionId public function Returns the latest revision identifier for an entity. Overrides RevisionableStorageInterface::getLatestRevisionId
ContentEntityStorageBase::getLatestTranslationAffectedRevisionId public function Returns the latest revision affecting the specified translation. Overrides TranslatableRevisionableStorageInterface::getLatestTranslationAffectedRevisionId
ContentEntityStorageBase::getRevisionTranslationMergeSkippedFieldNames protected function Returns an array of field names to skip when merging revision translations.
ContentEntityStorageBase::hasFieldValueChanged protected function Checks whether the field values changed compared to the original entity.
ContentEntityStorageBase::initFieldValues protected function Initializes field values.
ContentEntityStorageBase::invokeFieldMethod protected function Invokes a method on the Field objects within an entity.
ContentEntityStorageBase::invokeFieldPostSave protected function Invokes the post save method on the Field objects within an entity.
ContentEntityStorageBase::invokeHook protected function Invokes a hook on behalf of the entity. Overrides EntityStorageBase::invokeHook 1
ContentEntityStorageBase::invokeStorageLoadHook protected function Invokes hook_entity_storage_load().
ContentEntityStorageBase::invokeTranslationHooks protected function Checks translation statuses and invoke the related hooks if needed.
ContentEntityStorageBase::isAnyRevisionTranslated protected function Checks whether any entity revision is translated.
ContentEntityStorageBase::isAnyStoredRevisionTranslated protected function Checks whether any stored entity revision is translated.
ContentEntityStorageBase::loadMultipleRevisions public function Loads multiple entity revisions. Overrides RevisionableStorageInterface::loadMultipleRevisions 1
ContentEntityStorageBase::loadRevision public function Load a specific entity revision. Overrides EntityStorageInterface::loadRevision 1
ContentEntityStorageBase::loadUnchanged public function Loads an unchanged entity from the database. Overrides EntityStorageBase::loadUnchanged
ContentEntityStorageBase::onFieldDefinitionCreate public function Reacts to the creation of a field. Overrides FieldDefinitionListenerInterface::onFieldDefinitionCreate
ContentEntityStorageBase::onFieldDefinitionUpdate public function Reacts to the update of a field. Overrides FieldDefinitionListenerInterface::onFieldDefinitionUpdate
ContentEntityStorageBase::populateAffectedRevisionTranslations protected function Populates the affected flag for all the revision translations.
ContentEntityStorageBase::preLoad protected function Gathers entities from a 'preload' step. Overrides EntityStorageBase::preLoad
ContentEntityStorageBase::purgeFieldData public function Purges a batch of field data. Overrides FieldableEntityStorageInterface::purgeFieldData
ContentEntityStorageBase::resetCache public function Resets the internal, static entity cache. Overrides EntityStorageBase::resetCache 1
ContentEntityStorageBase::setPersistentCache protected function Stores entities in the persistent cache backend.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
DeprecatedServicePropertyTrait::__get public function Allows to access deprecated/removed properties.
EntityHandlerBase::$moduleHandler protected property The module handler to invoke hooks on. 2
EntityHandlerBase::moduleHandler protected function Gets the module handler. 2
EntityHandlerBase::setModuleHandler public function Sets the module handler for this handler.
EntityStorageBase::$entityClass protected property Name of the entity class.
EntityStorageBase::$entityType protected property Information about the entity type.
EntityStorageBase::$entityTypeId protected property Entity type ID for this storage.
EntityStorageBase::$idKey protected property Name of the entity's ID field in the entity database table.
EntityStorageBase::$memoryCache protected property The memory cache.
EntityStorageBase::$memoryCacheTag protected property The memory cache cache tag.
EntityStorageBase::$uuidKey protected property Name of entity's UUID database table field, if it supports UUIDs. 1
EntityStorageBase::$uuidService protected property The UUID service. 1
EntityStorageBase::buildCacheId protected function Builds the cache ID for the passed in entity ID. 1
EntityStorageBase::getAggregateQuery public function Gets an aggregated query instance. Overrides EntityStorageInterface::getAggregateQuery
EntityStorageBase::getEntityType public function Gets the entity type definition. Overrides EntityStorageInterface::getEntityType
EntityStorageBase::getEntityTypeId public function Gets the entity type ID. Overrides EntityStorageInterface::getEntityTypeId
EntityStorageBase::getFromStaticCache protected function Gets entities from the static cache.
EntityStorageBase::getQuery public function Gets an entity query instance. Overrides EntityStorageInterface::getQuery
EntityStorageBase::hasData public function Determines if the storage contains any data. Overrides EntityStorageInterface::hasData 3
EntityStorageBase::load public function Loads one entity. Overrides EntityStorageInterface::load 2
EntityStorageBase::loadByProperties public function Load entities by their property values. Overrides EntityStorageInterface::loadByProperties 3
EntityStorageBase::setStaticCache protected function Stores entities in the static entity cache.
EntityStorageInterface::FIELD_LOAD_CURRENT constant Load the most recent version of an entity's field data.
EntityStorageInterface::FIELD_LOAD_REVISION constant Load the version of an entity's field data specified in the entity.
SqlContentEntityStorage::$baseTable protected property The base table of the entity.
SqlContentEntityStorage::$database protected property Active database connection.
SqlContentEntityStorage::$dataTable protected property The table that stores properties, if the entity has multilingual support.
SqlContentEntityStorage::$defaultLangcodeKey protected property The default language entity key.
SqlContentEntityStorage::$entityTypeManager protected property The entity type manager.
SqlContentEntityStorage::$fieldStorageDefinitions protected property The entity type's field storage definitions.
SqlContentEntityStorage::$langcodeKey protected property The entity langcode key. Overrides EntityStorageBase::$langcodeKey
SqlContentEntityStorage::$languageManager protected property The language manager.
SqlContentEntityStorage::$revisionDataTable protected property The table that stores revision field data if the entity supports revisions.
SqlContentEntityStorage::$revisionKey protected property Name of entity's revision database table field, if it supports revisions.
SqlContentEntityStorage::$revisionTable protected property The table that stores revisions, if the entity supports revisions.
SqlContentEntityStorage::$storageSchema protected property The entity type's storage schema object.
SqlContentEntityStorage::$tableMapping protected property The mapping of field columns to SQL tables.
SqlContentEntityStorage::$temporary protected property Whether this storage should use the temporary table mapping.
SqlContentEntityStorage::buildPropertyQuery protected function Builds an entity query. Overrides EntityStorageBase::buildPropertyQuery
SqlContentEntityStorage::buildQuery protected function Builds the query to load the entity.
SqlContentEntityStorage::countFieldData public function Determines the number of entities with values for a given field. Overrides FieldableEntityStorageInterface::countFieldData
SqlContentEntityStorage::createInstance public static function Instantiates a new instance of this entity handler. Overrides ContentEntityStorageBase::createInstance 1
SqlContentEntityStorage::deleteFromDedicatedTables protected function Deletes values of fields in dedicated tables for all revisions.
SqlContentEntityStorage::deleteRevisionFromDedicatedTables protected function Deletes values of fields in dedicated tables for all revisions.
SqlContentEntityStorage::doDeleteFieldItems protected function Deletes entity field values from the storage. Overrides ContentEntityStorageBase::doDeleteFieldItems
SqlContentEntityStorage::doDeleteRevisionFieldItems protected function Deletes field values of an entity revision from the storage. Overrides ContentEntityStorageBase::doDeleteRevisionFieldItems
SqlContentEntityStorage::doLoadMultiple protected function Performs storage-specific loading of entities. Overrides EntityStorageBase::doLoadMultiple
SqlContentEntityStorage::doLoadMultipleRevisionsFieldItems protected function Actually loads revision field item values from the storage. Overrides ContentEntityStorageBase::doLoadMultipleRevisionsFieldItems
SqlContentEntityStorage::doLoadRevisionFieldItems protected function Actually loads revision field item values from the storage. Overrides ContentEntityStorageBase::doLoadRevisionFieldItems
SqlContentEntityStorage::doSaveFieldItems protected function Writes entity field values to the storage. Overrides ContentEntityStorageBase::doSaveFieldItems 1
SqlContentEntityStorage::finalizePurge public function Performs final cleanup after all data of a field has been purged. Overrides ContentEntityStorageBase::finalizePurge
SqlContentEntityStorage::getBaseTable public function Gets the base table name.
SqlContentEntityStorage::getCustomTableMapping public function Gets a table mapping for the specified entity type and storage definitions.
SqlContentEntityStorage::getDataTable public function Gets the data table name.
SqlContentEntityStorage::getFieldStorageDefinitions Deprecated public function Gets the base field definitions for a content entity type.
SqlContentEntityStorage::getFromStorage protected function Gets entities from the storage.
SqlContentEntityStorage::getQueryServiceName protected function Gets the name of the service for the query for this entity storage. Overrides EntityStorageBase::getQueryServiceName
SqlContentEntityStorage::getRevisionDataTable public function Gets the revision data table name.
SqlContentEntityStorage::getRevisionTable public function Gets the revision table name.
SqlContentEntityStorage::getStorageSchema protected function Gets the entity type's storage schema object.
SqlContentEntityStorage::getTableMapping public function Gets a table mapping for the entity's SQL tables. Overrides SqlEntityStorageInterface::getTableMapping
SqlContentEntityStorage::has protected function Determines if this entity already exists in storage. Overrides EntityStorageBase::has
SqlContentEntityStorage::initTableLayout protected function Initializes table name variables.
SqlContentEntityStorage::isColumnSerial protected function Checks whether a field column should be treated as serial. 1
SqlContentEntityStorage::loadFromDedicatedTables protected function Loads values of fields stored in dedicated tables for a group of entities.
SqlContentEntityStorage::loadFromSharedTables protected function Loads values for fields stored in the shared data tables.
SqlContentEntityStorage::mapFromStorageRecords protected function Maps from storage records to entity objects, and attaches fields. Overrides EntityStorageBase::mapFromStorageRecords
SqlContentEntityStorage::mapToDataStorageRecord protected function Maps from an entity object to the storage record of the field data.
SqlContentEntityStorage::mapToStorageRecord protected function Maps from an entity object to the storage record.
SqlContentEntityStorage::onBundleCreate public function Reacts to a bundle being created. Overrides EntityBundleListenerInterface::onBundleCreate
SqlContentEntityStorage::onBundleDelete public function Reacts to a bundle being deleted. Overrides EntityBundleListenerInterface::onBundleDelete
SqlContentEntityStorage::onEntityTypeCreate public function Reacts to the creation of the entity type. Overrides EntityTypeListenerInterface::onEntityTypeCreate
SqlContentEntityStorage::onEntityTypeDelete public function Reacts to the deletion of the entity type. Overrides EntityTypeListenerInterface::onEntityTypeDelete
SqlContentEntityStorage::onEntityTypeUpdate public function Reacts to the update of the entity type. Overrides EntityTypeListenerInterface::onEntityTypeUpdate
SqlContentEntityStorage::onFieldableEntityTypeCreate public function Reacts to the creation of the fieldable entity type. Overrides EntityTypeListenerInterface::onFieldableEntityTypeCreate
SqlContentEntityStorage::onFieldableEntityTypeUpdate public function Reacts to the update of a fieldable entity type. Overrides EntityTypeListenerInterface::onFieldableEntityTypeUpdate
SqlContentEntityStorage::onFieldDefinitionDelete public function Reacts to the deletion of a field. Overrides ContentEntityStorageBase::onFieldDefinitionDelete
SqlContentEntityStorage::onFieldStorageDefinitionCreate public function Reacts to the creation of a field storage definition. Overrides ContentEntityStorageBase::onFieldStorageDefinitionCreate
SqlContentEntityStorage::onFieldStorageDefinitionDelete public function Reacts to the deletion of a field storage definition. Overrides ContentEntityStorageBase::onFieldStorageDefinitionDelete
SqlContentEntityStorage::onFieldStorageDefinitionUpdate public function Reacts to the update of a field storage definition. Overrides ContentEntityStorageBase::onFieldStorageDefinitionUpdate
SqlContentEntityStorage::purgeFieldItems protected function Removes field items from storage per entity during purge. Overrides ContentEntityStorageBase::purgeFieldItems
SqlContentEntityStorage::readFieldItemsToPurge protected function Reads values to be purged for a single field. Overrides ContentEntityStorageBase::readFieldItemsToPurge
SqlContentEntityStorage::requiresEntityDataMigration public function Checks if existing data would be lost if the schema changes were applied. Overrides EntityStorageSchemaInterface::requiresEntityDataMigration
SqlContentEntityStorage::requiresEntityStorageSchemaChanges public function Checks if the changes to the entity type requires storage schema changes. Overrides EntityStorageSchemaInterface::requiresEntityStorageSchemaChanges
SqlContentEntityStorage::requiresFieldDataMigration public function Checks if existing data would be lost if the schema changes were applied. Overrides DynamicallyFieldableEntityStorageSchemaInterface::requiresFieldDataMigration
SqlContentEntityStorage::requiresFieldStorageSchemaChanges public function Checks if the changes to the storage definition requires schema changes. Overrides DynamicallyFieldableEntityStorageSchemaInterface::requiresFieldStorageSchemaChanges
SqlContentEntityStorage::restore public function Restores a previously saved entity. Overrides EntityStorageBase::restore
SqlContentEntityStorage::save public function Saves the entity permanently. Overrides EntityStorageBase::save 1
SqlContentEntityStorage::saveRevision protected function Saves an entity revision.
SqlContentEntityStorage::saveToDedicatedTables protected function Saves values of fields that use dedicated tables. 1
SqlContentEntityStorage::saveToSharedTables protected function Saves fields that use the shared tables.
SqlContentEntityStorage::setEntityType public function Updates the wrapped entity type definition.
SqlContentEntityStorage::setFieldStorageDefinitions public function Updates the internal list of field storage definitions.
SqlContentEntityStorage::setTableMapping public function Sets the wrapped table mapping definition.
SqlContentEntityStorage::setTemporary public function Changes the temporary state of the storage.
SqlContentEntityStorage::storageDefinitionIsDeleted Deprecated protected function Determines whether the passed field has been already deleted.
SqlContentEntityStorage::wrapSchemaException protected function Wraps a database schema exception into an entity storage exception.
SqlContentEntityStorage::__construct public function Constructs a SqlContentEntityStorage object. Overrides ContentEntityStorageBase::__construct 1
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.
YamlFormSubmissionStorage::$elementDataSchema protected property Array used to element data schema.
YamlFormSubmissionStorage::create public function Constructs a new entity object, without permanently saving it. Overrides EntityStorageBase::create
YamlFormSubmissionStorage::delete public function Deletes permanently saved entities. Overrides SqlContentEntityStorage::delete
YamlFormSubmissionStorage::deleteAll public function Delete all form submissions. Overrides YamlFormSubmissionStorageInterface::deleteAll
YamlFormSubmissionStorage::deleteData protected function Delete form submission data fromthe 'yamlform_submission_data' table.
YamlFormSubmissionStorage::doCreate protected function Performs storage-specific creation of entities. Overrides ContentEntityStorageBase::doCreate
YamlFormSubmissionStorage::doPostSave protected function Performs post save entity processing. Overrides ContentEntityStorageBase::doPostSave
YamlFormSubmissionStorage::doPreSave protected function Performs presave entity processing. Overrides ContentEntityStorageBase::doPreSave
YamlFormSubmissionStorage::doSave protected function Performs storage-specific saving of the entity. Overrides ContentEntityStorageBase::doSave
YamlFormSubmissionStorage::getColumns public function Get submission columns used to display results table. Overrides YamlFormSubmissionStorageInterface::getColumns
YamlFormSubmissionStorage::getCustomColumns public function Get customized submission columns used to display custom table. Overrides YamlFormSubmissionStorageInterface::getCustomColumns
YamlFormSubmissionStorage::getCustomSetting public function Get customize setting. Overrides YamlFormSubmissionStorageInterface::getCustomSetting
YamlFormSubmissionStorage::getDefaultColumns public function Get default submission columns used to display results. Overrides YamlFormSubmissionStorageInterface::getDefaultColumns
YamlFormSubmissionStorage::getFieldDefinitions public function Get form submission entity field definitions. Overrides YamlFormSubmissionStorageInterface::getFieldDefinitions
YamlFormSubmissionStorage::getFirstSubmission public function Get a form's first submission. Overrides YamlFormSubmissionStorageInterface::getFirstSubmission
YamlFormSubmissionStorage::getLastSubmission public function Get a form's last submission. Overrides YamlFormSubmissionStorageInterface::getLastSubmission
YamlFormSubmissionStorage::getMaxSerial public function Returns a form's max serial number. Overrides YamlFormSubmissionStorageInterface::getMaxSerial
YamlFormSubmissionStorage::getMaxSubmissionId public function Get the maximum sid. Overrides YamlFormSubmissionStorageInterface::getMaxSubmissionId
YamlFormSubmissionStorage::getNextSerial protected function Returns the next serial number.
YamlFormSubmissionStorage::getNextSubmission public function Get a form submission's next sibling. Overrides YamlFormSubmissionStorageInterface::getNextSubmission
YamlFormSubmissionStorage::getPreviousSubmission public function Get a form submission's previous sibling. Overrides YamlFormSubmissionStorageInterface::getPreviousSubmission
YamlFormSubmissionStorage::getSiblingSubmission protected function
YamlFormSubmissionStorage::getSourceEntityTypes public function Get form submission source entity types. Overrides YamlFormSubmissionStorageInterface::getSourceEntityTypes
YamlFormSubmissionStorage::getTerminusSubmission protected function
YamlFormSubmissionStorage::getTotal public function Get the total number of submissions. Overrides YamlFormSubmissionStorageInterface::getTotal
YamlFormSubmissionStorage::invokeYamlFormElements public function Invoke a form submission's form's elements method. Overrides YamlFormSubmissionStorageInterface::invokeYamlFormElements
YamlFormSubmissionStorage::invokeYamlFormHandlers public function Invoke a form submission's form's handlers method. Overrides YamlFormSubmissionStorageInterface::invokeYamlFormHandlers
YamlFormSubmissionStorage::loadData protected function Save form submission data from the 'yamlform_submission_data' table.
YamlFormSubmissionStorage::loadDraft public function Get form submission draft. Overrides YamlFormSubmissionStorageInterface::loadDraft
YamlFormSubmissionStorage::loadMultiple public function Loads one or more entities. Overrides EntityStorageBase::loadMultiple
YamlFormSubmissionStorage::postLoad protected function Attaches data to entities upon loading. Overrides EntityStorageBase::postLoad
YamlFormSubmissionStorage::saveData protected function Save form submission data to the 'yamlform_submission_data' table.
YamlFormSubmissionStorageInterface::SAVED_DISABLED constant Return status for saving of YAML forb submission when saving results is disabled.