entity_agree-2.0.x-dev/src/Plugin/views/field/AgreementStatus.php

src/Plugin/views/field/AgreementStatus.php
<?php

namespace Drupal\entity_agree\Plugin\views\field;

use Drupal\Core\Form\FormStateInterface;
use Drupal\entity_agree\Plugin\views\AgreementViewsPluginTrait;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Field plugin to display agreement status.
 *
 * @ViewsField("entity_agree_agreement_status")
 */
class AgreementStatus extends FieldPluginBase {

  use AgreementViewsPluginTrait;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    $field = parent::create($container, $configuration, $plugin_id, $plugin_definition);
    $field->entityRepository = $container->get('entity.repository');
    return $field;
  }

  /**
   * {@inheritdoc}
   */
  public function defineOptions() {
    return $this->defineStatusOptions(parent::defineOptions());
  }

  /**
   * {@inheritdoc}
   */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    $form['pending_text'] = $this->buildStatusOptionElement($this->t('Pending text'), $this->options['pending_text']);
    $form['complete_text'] = $this->buildStatusOptionElement($this->t('Complete text'), $this->options['complete_text']);
    parent::buildOptionsForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function query() {
    $this->ensureMyTable();
    $this->field_alias = $this->query->addField(NULL, "$this->realField IS NOT NULL", 'agreement_status');
  }

  /**
   * {@inheritdoc}
   */
  public function render(ResultRow $values) {
    return $this->getValue($values) ? $this->options['complete_text'] : $this->options['pending_text'];
  }

}

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

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