カスタムアクションを作成する方法

カテゴリ コンテンツの管理 コアバージョン 8.4x 関連モジュール Action

modules/custom/youmodule/config/system.action.your_action_name_action.yml

id: your_action_name_action
label: 'ノードにXXを事をする'
status: true
langcode: en
type: node
plugin: your_action_name_action
dependencies:
  module:
    - node

modules/custom/youmodule/src/Plugin/Action/YourActionName.php

<?php

namespace Drupal\image_manager\Plugin\Action;

use Drupal\Core\Action\ActionBase;
use Drupal\Core\Session\AccountInterface;
use Drupal\node\Entity\Node;

/**
 * ノードをXXする。
 *
 * @Action(
 *   id = "your_action_name_action",
 *   label = @Translation("Your Action Name"),
 *   type = "node"
 * )
 */
class YourActionName extends ActionBase {

  /**
   * {@inheritdoc}
   */
  public function execute($node = NULL) {
    $node----->set('field_xxxxx', $node->get('field_yyyyy')->value + 1);
    〜
    $node->save();
  }
​
  /**
   * {@inheritdoc}
   */
  public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
    $isEnable = 〜
    // = $object->access('delete', $account, $return_as_object); とか
    return $isEnable;
  }
}

OTHER FAQ

Drupal開発・運用の疑問/質問の答えはここに

無料ユーザー登録すると質問できます。

カテゴリ Core Ver. 関連モジュール降順で並び替える タイトル
フォーム 7.15 Webform Webform - 確認ページの多言語化
フォーム 7.43 Webform フォーム関数が実行されるタイミングについて
アップデート 7.15 Webform Backup_and_Migrate drupal7.12 -> drupal7.14アップデートメモ
フォーム 7.15 Webform Template Webformを複写したい
Japanese mail 7.15 Webform, Mail System, Mime Mail, Japanese Mail Helper Webformから文字化けしないメール送信を行うには
フォーム 7.16 Webform, Mail System, Mime Mail, Jp Mail Helper 送信メールのサブジェクトが長いと文字化けする
サイトの環境設定 7.59 さくらのレンタルサーバー php Options さくらのレンタルサーバーで パブリック/プライベートディレクトリにファイルが書き込まれないとき

ページ