marketo_suite-1.0.x-dev/src/MarketoFormEntityStorage.php

src/MarketoFormEntityStorage.php
<?php

namespace Drupal\e3_marketo;

use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\e3_marketo\Entity\MarketoFormEntityInterface;

/**
 * Defines the storage handler class for Marketo form entity entities.
 *
 * This extends the base storage class, adding required special handling for
 * Marketo form entity entities.
 *
 * @ingroup e3_marketo
 */
class MarketoFormEntityStorage extends SqlContentEntityStorage implements MarketoFormEntityStorageInterface {

  /**
   * {@inheritdoc}
   */
  public function revisionIds(MarketoFormEntityInterface $entity) : array {
    return $this->database->select('marketo_form_revision', 'mfr')
      ->fields('mfr', ['vid'])
      ->condition('mfr.id', $entity->id())
      ->orderBy('mfr.vid')
      ->execute()
      ->fetchCol();
  }

  /**
   * {@inheritdoc}
   */
  public function userRevisionIds(AccountInterface $account) : array {
    return $this->database->select('marketo_form_field_revision', 'mfr')
      ->fields('mfr', ['vid'])
      ->condition('mfr.uid', (string) $account->id())
      ->orderBy('mfr.vid')
      ->execute()
      ->fetchCol();
  }

  /**
   * {@inheritdoc}
   */
  public function countDefaultLanguageRevisions(MarketoFormEntityInterface $entity) : int {
    return $this->database->select('marketo_form_field_revision', 'mfr')
      ->condition('mfr.id', $entity->id())
      ->condition('mfr.default_langcode', "1")
      ->countQuery()
      ->execute()
      ->fetchField();
  }

  /**
   * {@inheritdoc}
   */
  public function clearRevisionsLanguage(LanguageInterface $language) : ?int {
    return $this->database->update('marketo_form_revision')
      ->fields(['langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED])
      ->condition('langcode', $language->getId())
      ->execute();
  }

  /**
   * {@inheritdoc}
   */
  public function loadByMarketoId(string $marketo_id) : array {
    $matching_forms = $this->loadByProperties(['marketo_form_id' => $marketo_id]);
    return $matching_forms ?: [];
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc