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

カテゴリ コンテンツの管理 コアバージョン 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 Pagenation 一つの長いページをBookなどのように連続して読ませることはできますか?
コンテンツの管理 7.38 Block Views node ノードページの編集タブをコンテキストメニューにしたい
コンテンツの管理 8.4x Action カスタムアクションを作成する方法
コンテンツの管理 8.9.x Dialog Modal Canvas drupal 8 の標準機能のダイアログ/ポップアップを表示する方法
コンテンツの管理 6.x Views Flag Calendar 空き室予約のような仕組みは実現できますか?
コンテンツの管理 8.5.x Field File コンテンツのフィールドの表示について
コンテンツの管理 8.4x Entity EntityをPropertyで探す(クエリする)方法
コンテンツの管理 7,51 Views Data Export Views Data ExportでCSVデータが欠けてしまう
コンテンツの管理 7.15 Content Access 簡単に閲覧制限を行うには?
コンテンツの管理 7.16 PHP 好きなところにノードを埋め込みたい
コンテンツの管理 8.6.x Commerce Commerce orderからすべての商品名を取得する方法
サイトの構築 7.41 Rules Paygent モジュールについて
サイトの構築 7.34 ECK Entityの使い方について
サイトの構築 7.19 Plesk Pleskでdrupal7(プライベートファイルシステム)を使う場合の注意点
サイトの構築 7.59 Drupal.ajax drupal 7 で Uncaught TypeError: Drupal.ajax is undefined となったときの対応方法
サイトの構築 7.31 Views ブロックViewsの絞り込みが表示されない
サイトの構築 7.23 Conditional fields ノード編集フォームを動的にしたい
サイトの構築 7.22 Views Devel Viewsの設定ページが変に?
サイトの構築 7.27 Context block ページ別、カテゴリ別等でブロックの表示有無を簡単にするには
サイトの構築 7.38 deployment 冗長構成におけるアップロードおよび時間指定公開について

ページ