xtcentity-2.x-dev/src/Plugin/XtcAction/Field.php

src/Plugin/XtcAction/Field.php
<?php


namespace Drupal\xtcentity\Plugin\XtcAction;


use Drupal\Core\Entity\ContentEntityBase;
use Drupal\xtc\PluginManager\XtcAction\XtcActionPluginBase;

/**
 * Plugin implementation of the xtc_action.
 *
 * @XtcAction(
 *   id = "field",
 *   label = @Translation("Field for XTC Action"),
 *   description = @Translation("Field for XTC Action description.")
 * )
 */
class Field extends XtcActionPluginBase {

  /**
   * @param array $options
   *
   * @return array
   * @throws \Drupal\Core\TypedData\Exception\MissingDataException
   */
  public function from($options = []) {
    $content = [
      'options' => $options,
      'values' => [],
    ];
    /** @var ContentEntityBase $entity */
    $entity = $options['entity'] ?? NULL;
    $settings = $options['settings'] ?? NULL;

    $fieldname = $settings['field'] ?? NULL;

    if(!empty($fieldname) && !empty($entity->get($fieldname))) {
      $value = $entity->get($fieldname)->first();
      if(!empty($value)) {
        $content['values'][] = $value->getValue()['value'] ?? '';
      }
    }
    return $content;
  }

  public function to($options = []) {
    parent::to(); // TODO: Change the autogenerated stub
  }

}

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

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