Skip to content
Snippets Groups Projects
Commit b48e099f authored by Will Tate's avatar Will Tate Committed by Stephen Mustgrave
Browse files

Resolve #3489268 "Plugin for single"

parent eb20ea4d
No related branches found
No related tags found
1 merge request!19Resolve #3489268 "Plugin for single"
Pipeline #387456 passed with warnings
################ ################# DrupalCI GitLabCI template
# DrupalCI GitLabCI template
# #
# Gitlab-ci.yml to replicate DrupalCI testing for Contrib # Gitlab-ci.yml to replicate DrupalCI testing for Contrib
# #
# With thanks to: # With thanks to:
# * The GitLab Acceleration Initiative participants # * The GitLab Acceleration Initiative participants
# * DrupalSpoons # * DrupalSpoons
################ ################
...@@ -11,24 +10,24 @@ ...@@ -11,24 +10,24 @@
################ ################
# Guidelines # Guidelines
# #
# This template is designed to give any Contrib maintainer everything they need to test, without requiring modification. It is also designed to keep up to date with Core Development automatically through the use of include files that can be centrally maintained. # This template is designed to give any Contrib maintainer everything they need to test, without requiring modification. It is also designed to keep up to date with Core Development automatically through the use of include files that can be centrally maintained.
# #
# However, you can modify this template if you have additional needs for your project. # However, you can modify this template if you have additional needs for your project.
################ ################
################ ################
# Includes # Includes
# #
# Additional configuration can be provided through includes. # Additional configuration can be provided through includes.
# One advantage of include files is that if they are updated upstream, the changes affect all pipelines using that include. # One advantage of include files is that if they are updated upstream, the changes affect all pipelines using that include.
# #
# Includes can be overridden by re-declaring anything provided in an include, here in gitlab-ci.yml # Includes can be overridden by re-declaring anything provided in an include, here in gitlab-ci.yml
# https://docs.gitlab.com/ee/ci/yaml/includes.html#override-included-configuration-values # https://docs.gitlab.com/ee/ci/yaml/includes.html#override-included-configuration-values
################ ################
include: include:
################ ################
# DrupalCI includes: # DrupalCI includes:
# As long as you include this, any future includes added by the Drupal Association will be accessible to your pipelines automatically. # As long as you include this, any future includes added by the Drupal Association will be accessible to your pipelines automatically.
# View these include files at https://git.drupalcode.org/project/gitlab_templates/ # View these include files at https://git.drupalcode.org/project/gitlab_templates/
################ ################
...@@ -44,54 +43,13 @@ include: ...@@ -44,54 +43,13 @@ include:
# #
# These are the variables provided to the Run Pipeline form that a user may want to override. # These are the variables provided to the Run Pipeline form that a user may want to override.
# #
# Docs at https://git.drupalcode.org/project/gitlab_templates/-/blob/1.0.x/includes/include.drupalci.variables.yml # Docs at https://git.drupalcode.org/project/gitlab_templates/-/blob/main/includes/include.drupalci.variables.yml
################ ################
# variables: variables:
# SKIP_ESLINT: '1' _PHPUNIT_CONCURRENT: '1'
OPT_IN_TEST_MAX_PHP: '1'
OPT_IN_TEST_PREVIOUS_MAJOR: '1'
################################################################################### OPT_IN_TEST_NEXT_MAJOR: '1'
# OPT_IN_TEST_NEXT_MINOR: '1'
# * # CSpell Customization.
# /( _CSPELL_WORDS: "Beltofte,beltofte,datasource,Jens,Mustgrave,smustgrave"
# ((((,
# /(((((((
# ((((((((((*
# ,(((((((((((((((
# ,(((((((((((((((((((
# ((((((((((((((((((((((((*
# *(((((((((((((((((((((((((((((
# ((((((((((((((((((((((((((((((((((*
# *(((((((((((((((((( .((((((((((((((((((
# ((((((((((((((((((. /(((((((((((((((((*
# /((((((((((((((((( .(((((((((((((((((,
# ,(((((((((((((((((( ((((((((((((((((((
# .(((((((((((((((((((( .(((((((((((((((((
# ((((((((((((((((((((((( ((((((((((((((((/
# (((((((((((((((((((((((((((/ ,(((((((((((((((*
# .((((((((((((((/ /(((((((((((((. ,(((((((((((((((
# *(((((((((((((( ,(((((((((((((/ *((((((((((((((.
# ((((((((((((((, /(((((((((((((. ((((((((((((((,
# (((((((((((((/ ,(((((((((((((* ,(((((((((((((,
# *((((((((((((( .((((((((((((((( ,(((((((((((((
# ((((((((((((/ /((((((((((((((((((. ,((((((((((((/
# ((((((((((((( *(((((((((((((((((((((((* *((((((((((((
# ((((((((((((( ,(((((((((((((..((((((((((((( *((((((((((((
# ((((((((((((, /((((((((((((* /((((((((((((/ ((((((((((((
# ((((((((((((( /((((((((((((/ (((((((((((((* ((((((((((((
# (((((((((((((/ /(((((((((((( ,((((((((((((, *((((((((((((
# (((((((((((((( *(((((((((((/ *((((((((((((. ((((((((((((/
# *((((((((((((((((((((((((((, /(((((((((((((((((((((((((
# ((((((((((((((((((((((((( ((((((((((((((((((((((((,
# .(((((((((((((((((((((((/ ,(((((((((((((((((((((((
# ((((((((((((((((((((((/ ,(((((((((((((((((((((/
# *((((((((((((((((((((( (((((((((((((((((((((,
# ,(((((((((((((((((((((, ((((((((((((((((((((/
# ,(((((((((((((((((((((* /((((((((((((((((((((
# ((((((((((((((((((((((, ,/((((((((((((((((((((,
# ,(((((((((((((((((((((((((((((((((((((((((((((((((((
# .(((((((((((((((((((((((((((((((((((((((((((((
# .((((((((((((((((((((((((((((((((((((,.
# .,(((((((((((((((((((((((((.
#
###################################################################################
...@@ -26,7 +26,7 @@ function search_api_exclude_entity_form_field_storage_config_edit_form_alter(&$f ...@@ -26,7 +26,7 @@ function search_api_exclude_entity_form_field_storage_config_edit_form_alter(&$f
/** /**
* Implements hook_entity_field_access(). * Implements hook_entity_field_access().
*/ */
function search_api_exclude_entity_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL): AccessResultInterface { function search_api_exclude_entity_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, ?FieldItemListInterface $items = NULL): AccessResultInterface {
if ($field_definition->getType() == 'search_api_exclude_entity' && $operation == 'edit') { if ($field_definition->getType() == 'search_api_exclude_entity' && $operation == 'edit') {
return AccessResult::allowedIfHasPermission($account, 'edit search api exclude entity'); return AccessResult::allowedIfHasPermission($account, 'edit search api exclude entity');
} }
......
<?php
namespace Drupal\search_api_exclude_entity\Plugin\SingleContentSyncFieldProcessor;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\single_content_sync\SingleContentSyncFieldProcessorPluginBase;
/**
* Field processor plugin for the Search API Exclude Entity field.
*
* @SingleContentSyncFieldProcessor(
* id = "search_api_exclude_entity_field",
* label = @Translation("Search API Exclude Entity Field"),
* field_type = "search_api_exclude_entity"
* )
*/
class SearchApiExcludeEntityField extends SingleContentSyncFieldProcessorPluginBase {
/**
* {@inheritdoc}
*/
public function exportFieldValue(FieldItemListInterface $field): array {
// For a boolean field, return the field value.
return $field->getValue();
}
/**
* {@inheritdoc}
*/
public function importFieldValue(FieldableEntityInterface $entity, string $fieldName, array $value): void {
// Set the field value on the entity.
$entity->set($fieldName, $value);
}
}
...@@ -83,8 +83,8 @@ class SearchApiExcludeEntityProcessor extends ProcessorPluginBase implements Plu ...@@ -83,8 +83,8 @@ class SearchApiExcludeEntityProcessor extends ProcessorPluginBase implements Plu
$fields_config = $this->getConfiguration()['fields']; $fields_config = $this->getConfiguration()['fields'];
foreach ($this->index->getDatasources() as $datasource_id => $datasource) { foreach ($this->index->getDatasources() as $datasource_id => $datasource) {
$datasource_id_expl = explode(':', $datasource_id); $datasource_id_explode = explode(':', $datasource_id);
$entity_type = next($datasource_id_expl); $entity_type = next($datasource_id_explode);
$form['fields'][$entity_type] = [ $form['fields'][$entity_type] = [
'#type' => 'checkboxes', '#type' => 'checkboxes',
......
...@@ -5,13 +5,13 @@ namespace Drupal\Tests\search_api_exclude_entity\Unit\Processor; ...@@ -5,13 +5,13 @@ namespace Drupal\Tests\search_api_exclude_entity\Unit\Processor;
use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\Plugin\DataType\EntityAdapter; use Drupal\Core\Entity\Plugin\DataType\EntityAdapter;
use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Tests\search_api\Unit\Processor\TestItemsTrait;
use Drupal\Tests\UnitTestCase;
use Drupal\node\NodeInterface; use Drupal\node\NodeInterface;
use Drupal\search_api\IndexInterface; use Drupal\search_api\IndexInterface;
use Drupal\search_api\Item\ItemInterface; use Drupal\search_api\Item\ItemInterface;
use Drupal\search_api\Utility\Utility; use Drupal\search_api\Utility\Utility;
use Drupal\search_api_exclude_entity\Plugin\search_api\processor\SearchApiExcludeEntityProcessor; use Drupal\search_api_exclude_entity\Plugin\search_api\processor\SearchApiExcludeEntityProcessor;
use Drupal\Tests\search_api\Unit\Processor\TestItemsTrait;
use Drupal\Tests\UnitTestCase;
/** /**
* Tests the "Search API Exclude Entity" processor. * Tests the "Search API Exclude Entity" processor.
...@@ -133,7 +133,7 @@ class SearchApiExcludeEntityProcessorTest extends UnitTestCase { ...@@ -133,7 +133,7 @@ class SearchApiExcludeEntityProcessorTest extends UnitTestCase {
* @return \Drupal\search_api\Item\ItemInterface * @return \Drupal\search_api\Item\ItemInterface
* The mock search index item. * The mock search index item.
*/ */
protected function createMockItem(string $bundle, string $raw_id, FieldItemListInterface $field_value_1 = NULL, FieldItemListInterface $field_value_2 = NULL): ItemInterface { protected function createMockItem(string $bundle, string $raw_id, ?FieldItemListInterface $field_value_1 = NULL, ?FieldItemListInterface $field_value_2 = NULL): ItemInterface {
$node = $this->createMock(NodeInterface::class); $node = $this->createMock(NodeInterface::class);
$node->method('getEntityTypeId')->willReturn('node'); $node->method('getEntityTypeId')->willReturn('node');
$node->method('bundle')->willReturn($bundle); $node->method('bundle')->willReturn($bundle);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment