ifthenelse-8.x-1.x-dev-no-core/modules/contrib/if_then_else/src/core/Nodes/Actions/AddToLogAction/AddToLogAction.php

modules/contrib/if_then_else/src/core/Nodes/Actions/AddToLogAction/AddToLogAction.php
<?php

namespace Drupal\if_then_else\core\Nodes\Actions\AddToLogAction;

use Drupal\if_then_else\core\Nodes\Actions\Action;
use Drupal\if_then_else\Event\NodeSubscriptionEvent;
use Drupal\if_then_else\Event\NodeValidationEvent;

/**
 * Class defined to execute add to log action.
 */
class AddToLogAction extends Action {

  /**
   * Return node name.
   */
  public static function getName() {
    return 'add_to_log_action';
  }

  /**
   * {@inheritdoc}
   */
  public function registerNode(NodeSubscriptionEvent $event) {
    $event->nodes[static::getName()] = [
      'label' => t('Log'),
      'type' => 'action',
      'class' => 'Drupal\\if_then_else\\core\\Nodes\\Actions\\AddToLogAction\\AddToLogAction',
      'library' => 'if_then_else/AddToLogAction',
      'control_class_name' => 'AddToLogActionControl',
      'compare_options' => [
        ['code' => 'emergency', 'name' => 'Emergency'],
        ['code' => 'alert', 'name' => 'Alert'],
        ['code' => 'critical', 'name' => 'Critical'],
        ['code' => 'error', 'name' => 'Error'],
        ['code' => 'warning', 'name' => 'Warning'],
        ['code' => 'notice', 'name' => 'Notice'],
        ['code' => 'info', 'name' => 'Info'],
        ['code' => 'debug', 'name' => 'Debug'],
      ],
      'inputs' => [
        'message' => [
          'label' => t('Message'),
          'description' => t('Message string'),
          'sockets' => ['string'],
          'required' => TRUE,
        ],
      ],
    ];
  }

  /**
   * Validation function.
   */
  public function validateNode(NodeValidationEvent $event) {
    $data = $event->node->data;
    if (empty($data->selected_severity->code)) {
      $event->errors[] = t('Select at least one severity in "@node_name".', ['@node_name' => $event->node->name]);
    }
  }

  /**
   * Process add to log action node.
   */
  public function process() {
    $severity = $this->data->selected_severity->code;
    $set_message_text = $this->inputs['message'];
    if (!empty($severity) && !empty($set_message_text)) {
      \Drupal::logger('if_then_else')->{$severity}($set_message_text);
    }
    else {
      $this->setSuccess(FALSE);
      return;
    }
  }

}

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

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