66 parent::__construct($entity_type_manager->getDefinition(
'paragraphs_type'), $entity_type_manager->getStorage(
'paragraphs_type'));
67 $this->pluginId = $plugin_id;
68 $this->pluginDefinition = $plugin_definition;
75 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
79 $configuration[
'context'],
80 $container->get(
'entity_type.manager')
88 return 'paragraphs_editor_bundle_list_builder';
94 public function buildForm(array $form, FormStateInterface $form_state) {
95 $form[
'search_container'] = [
96 '#type' =>
'container',
99 'paragraphs-editor-bundle-selector-search',
104 'paragraphs_editor/core',
108 $form[
'search_container'][
'search'] = [
109 '#title' => $this->t(
'Search'),
110 '#type' =>
'textfield',
113 'paragraphs-editor-bundle-selector-search__input',
115 'autocomplete' =>
'off',
118 $form[
'search_container'][
'search_button'] = [
120 '#value' =>
'Search',
122 '#limit_validation_errors' => [],
124 'callback' => [get_class($this),
'ajaxSearch'],
125 'wrapper' =>
'paragraphs-editor-bundle-selector-options',
129 'paragraphs-editor-bundle-selector-search__submit',
135 '#prefix' =>
'<div id="paragraphs-editor-bundle-selector-options">',
136 '#suffix' =>
'</div>',
139 '#empty' => t(
'Could not find any matching options.', [
'@label' => $this->entityType->getLabel()]),
142 $input = $form_state->getUserInput();
143 $search = isset($input[
'search']) ? $input[
'search'] :
'';
144 $search = trim(preg_replace(
'/\(.*\)$/',
'', $search));
145 $entities = $this->
load($search);
146 foreach ($entities as $entity) {
148 if (isset($row[
'label'])) {
149 $row[
'label'] = [
'#markup' => $row[
'label']];
151 $form[
'options'][$entity->id()] = $row;
156 '#title' => $this->t(
'Cancel'),
157 '#url' => $this->context->createCommandUrl(
'cancel'),
180 public static function ajaxSearch(array $form, FormStateInterface $form_state) {
181 return $form[
'options'];
189 $header[
'label'] = t(
'Type');
190 $header[
'operations'] =
'';
197 public function buildRow(EntityInterface $entity) {
199 $row[
'label'] = $entity->label();
200 return $row + parent::buildRow($entity);
212 '#title' => t(
'Add'),
213 '#url' => $this->context->createCommandUrl(
'insert', [
214 'bundle_name' => $entity->id(),
229 public function validateForm(array &$form, FormStateInterface $form_state) {
236 public function submitForm(array &$form, FormStateInterface $form_state) {
243 public function load($search = NULL) {
245 $entities = $this->storage->loadMultiple($entity_ids);
249 uasort($entities, [$this->entityType->getClass(),
'sort']);
257 $query = $this->getStorage()->getQuery()
258 ->sort($this->entityType->getKey(
'id'));
261 $query->condition(
'label', $search,
'CONTAINS');
264 $this->context->getBundleFilter()->filterQuery($query);
268 $query->pager($this->limit);
270 $results = $query->execute();
271 return is_array($results) ? $results : [];
__construct($plugin_id, $plugin_definition, CommandContextInterface $context, EntityTypeManagerInterface $entity_type_manager)
buildOperations(EntityInterface $entity)
validateForm(array &$form, FormStateInterface $form_state)
static ajaxSearch(array $form, FormStateInterface $form_state)
buildForm(array $form, FormStateInterface $form_state)
getEntityIds($search=NULL)
buildRow(EntityInterface $entity)
submitForm(array &$form, FormStateInterface $form_state)
static create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition)