私が使用していますエンティティブラウザカスタムエンティティのエンティティ参照ベースフィールドのためのフォームウィジェットとして(Drupalの8で2.xの-devのを)。エンティティブラウザが構成されている
- モーダルディスプレイとして、
- 単一のウィジェットで、
- 選択表示なし、
- エンティティブラウザーの一括選択フィールドを持つビューをウィジェットとして使用し、
- 選択したエンティティを参照フィールドの現在の選択に追加します。
エンティティの選択は正常に機能しています。ただし、エンティティ参照フィールドには重複があってはなりません。
重複のないエンティティの選択を容易にするために、エンティティブラウザビューの結果から既に選択されているエンティティをフィルタリングします。したがって、ユーザーには選択されていないエンティティのみが表示されます。
この目的のために、エンティティIDのコンテキストデフォルト引数としてエンティティブラウザー選択ストレージを公開するカスタムビューargument_defaultプラグインを作成しました。
<?php
namespace Drupal\my_module\Plugin\views\argument_default;
use Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface;
use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* The entity browser selection argument default handler.
*
* @ViewsArgumentDefault(
* id = "entity_browser_selection",
* title = @Translation("Entity Browser Selection")
* )
*/
class EntityBrowserSelection extends ArgumentDefaultPluginBase {
/**
* The selection storage.
*
* @var \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface
*/
protected $selectionStorage;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, KeyValueStoreExpirableInterface $selection_storage) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->selectionStorage = $selection_storage;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('entity_browser.selection_storage')
);
}
/**
* {@inheritdoc}
*/
public function access() {
return $this->view->getDisplay()->pluginId === 'entity_browser';
}
/**
* {@inheritdoc}
*/
public function getArgument() {
$argument = NULL;
$current_request = $this->view->getRequest();
// Check if the widget context is available.
if ($current_request->query->has('uuid')) {
$uuid = $current_request->query->get('uuid');
if ($storage = $this->selectionStorage->get($uuid)) {
if (!empty($storage['selected_entities'])) {
$argument = $storage['selected_entities'];
}
}
}
return $argument;
}
}
私が直面している問題は、エンティティ参照フィールドで選択されているエンティティの数に関係なく、選択ストレージ内の現在の選択は常に空であり、モーダル選択を完了してエンティティブラウザを再度開いた後でもです。
エンティティブラウザーの選択ストレージに現在の選択を公開するには、何をする必要がありますか?
#default_value
)もフィルターと見なされる必要があります。