Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/4.0.x' into search-api
Browse files Browse the repository at this point in the history
* upstream/4.0.x:
  Support for basefield overrides (eileenmcnaughton#496)
  update tests, 10.3 official, and 5.75 (eileenmcnaughton#490)
  check for metatag_computed field, for Drupal entity based saves with Metatag 2.0 (eileenmcnaughton#489)
  use LoggerChannelFactoryInterface instead of default service (eileenmcnaughton#488)
  update tests for 10.3 and 11 (eileenmcnaughton#484)
  fix edge case updating base field definition for bundles (eileenmcnaughton#487)
  Add patch from https://www.drupal.org/project/civicrm_entity/issues/3447309. (eileenmcnaughton#486)
  Fix metatag not loading. (eileenmcnaughton#481)
  update settings form for D11 compatibility (eileenmcnaughton#485)
  adding logger parameter to ModulerInstaller service (eileenmcnaughton#483)
  update composer.json for Drupal 11 (eileenmcnaughton#482)
  deprecation fixes for D11 (eileenmcnaughton#480)
  Adds Checksum validation solution for Drupal Views (eileenmcnaughton#478)
  Add pcp. (eileenmcnaughton#477)
  supportedentities update AllCoreTables function (eileenmcnaughton#479)
  • Loading branch information
puresyntax71 committed Aug 22, 2024
2 parents 6a8dd20 + 2bfacc1 commit dd553c6
Show file tree
Hide file tree
Showing 14 changed files with 315 additions and 22 deletions.
15 changes: 10 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ jobs:
include:
- drupal: '10.2.*'
civicrm: '5.69.*'
- drupal: '10.2.*'
php: '8.1'
- drupal: '10.3.*'
civicrm: '5.75.*'
php: '8.3'
- drupal: '11.0.0-beta1@beta'
civicrm: 'dev-master'
php: '8.3'
name: Drupal ${{ matrix.drupal }} | CiviCRM ${{ matrix.civicrm }}
services:
mysql:
Expand All @@ -36,7 +41,7 @@ jobs:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: 8.1
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pdo, mysql, pdo_mysql, bcmath, soap, intl, gd, exif, iconv
coverage: none
tools: composer:v2
Expand Down Expand Up @@ -90,16 +95,16 @@ jobs:
run: php -S 127.0.0.1:8080 -t ~/drupal/web &
- name: Run PHPUnit
run: |
mkdir $BROWSERTEST_OUTPUT_DIRECTORY
mkdir -p $BROWSERTEST_OUTPUT_DIRECTORY
cd ~/drupal/web
../vendor/bin/phpunit -c core modules/contrib/civicrm_entity
env:
SYMFONY_DEPRECATIONS_HELPER: disabled
SIMPLETEST_DB: mysql://root:@127.0.0.1:${{ job.services.mysql.ports[3306] }}/db
SIMPLETEST_CIVICRM_DB: mysql://root:@127.0.0.1:${{ job.services.mysql.ports[3306] }}/db_civicrm
SIMPLETEST_BASE_URL: http://127.0.0.1:8080
MINK_DRIVER_ARGS_WEBDRIVER: '["chrome", {"browserName":"chrome","chromeOptions":{"args":["--disable-gpu", "--no-sandbox", "--headless"]}}, "http://127.0.0.1:9515"]'
BROWSERTEST_OUTPUT_DIRECTORY: '${{ runner.temp }}/browser_output'
MINK_DRIVER_ARGS_WEBDRIVER: '["chrome", {"browserName":"chrome","goog:chromeOptions":{"args":["--disable-gpu", "--no-sandbox", "--headless"]}}, "http://127.0.0.1:9515"]'
BROWSERTEST_OUTPUT_DIRECTORY: '/home/runner/drupal/web/sites/simpletest/browser_output'
- uses: actions/upload-artifact@v2
if: ${{ failure() || success() }}
with:
Expand Down
2 changes: 1 addition & 1 deletion civicrm_entity.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CiviCRM Entity
type: module
description: 'Expose CiviCRM entities as Drupal entities.'
package: CiviCRM
core_version_requirement: ^10
core_version_requirement: ^10.1 || ^11
dependencies:
- civicrm
- drupal:datetime
Expand Down
19 changes: 13 additions & 6 deletions civicrm_entity.module
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,14 @@ function civicrm_entity_entity_bundle_field_info(EntityTypeInterface $entity_typ
}
}
// Ensure all fields have a definition.
foreach ($base_field_definitions as $field_name => $definition) {
if (isset($result[$field_name])) {
continue;
if ($entity_type->get('civicrm_entity_ui_exposed') && $entity_type->hasKey('bundle')) {
foreach ($base_field_definitions as $field_name => $definition) {
if (isset($result[$field_name]) || isset($definition)) {
continue;
}
$field = BaseFieldOverride::createFromBaseFieldDefinition($base_field_definitions[$field_name], $bundle);
$result[$field_name] = $field;
}
$field = BaseFieldOverride::createFromBaseFieldDefinition($base_field_definitions[$field_name], $bundle);
$result[$field_name] = $field;
}
return $result;
}
Expand Down Expand Up @@ -486,7 +488,12 @@ function civicrm_entity_civicrm_pre($op, $objectName, $id, &$params) {
else {
// Special handling for EntityTag objects.
if ($objectName == 'EntityTag') {
$id = $storage->getEntityTagEntityId($params[0][0], $params[1]);
if (isset($params['entity_id']) && isset($params['entity_table'])) {
$id = $storage->getEntityTagEntityId($params['entity_id'], $params['entity_table']);
}
else {
$id = $storage->getEntityTagEntityId($params[0][0], $params[1]);
}
}
/** @var \Drupal\civicrm_entity\Entity\CivicrmEntity $entity */
$entity = $storage->load($id);
Expand Down
9 changes: 8 additions & 1 deletion civicrm_entity.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@ services:
class: Drupal\civicrm_entity\ModuleInstaller
decorates: module_installer
public: true
arguments: ['@civicrm_entity.module_installer.inner', '%app.root%', '@module_handler', '@kernel', '@database', '@update.update_hook_registry']
arguments: ['@civicrm_entity.module_installer.inner', '%app.root%', '@module_handler', '@kernel', '@database', '@update.update_hook_registry', '@logger.factory']
tags:
- { name: service_collector, tag: 'module_install.uninstall_validator', call: addUninstallValidator }

civicrm_entity.contact_checksum_access_checker:
class: Drupal\civicrm_entity\Access\ContactChecksumCheckAccess
autowire: true
arguments: ['@request_stack', '@civicrm_entity.api']
tags:
- {name: access_check, applies_to: _civicrm_entity_checksum_access_check }

civicrm_entity.search_api:
class: Drupal\civicrm_entity\EventSubscriber\SearchApiSubscriber
tags:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"homepage": "http://drupal.org/project/civicrm_entity",
"license": "GPL-2.0+",
"require": {
"drupal/core": "^10",
"drupal/core": "^10.1 || ^11",
"civicrm/civicrm-drupal-8": "*"
},
"require-dev": {
Expand Down
87 changes: 87 additions & 0 deletions src/Access/ContactChecksumCheckAccess.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

namespace Drupal\civicrm_entity\Access;

use Civi\Api4\Contact;
use Drupal\civicrm_entity\CiviCrmApiInterface;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Logger\LoggerChannelTrait;
use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Route;

/**
* Checks access for displaying views using the ContactChecksum plugin.
*/
class ContactChecksumCheckAccess implements AccessInterface {

use LoggerChannelTrait;

/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;

/**
* The CiviCRM API service.
*
* @var \Drupal\civicrm_entity\CiviCrmApiInterface
*/
protected $civicrmApi;

/**
* Constructs a ContactChecksumCheckAccess object.
*
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
* @param \Drupal\civicrm_entity\CiviCrmApiInterface $civicrm_api
* The CiviCRM API bridge.
*/
public function __construct(RequestStack $request_stack, CiviCrmApiInterface $civicrm_api) {
$this->requestStack = $request_stack;
$this->civicrmApi = $civicrm_api;
}

/**
* A custom access check.
*
* @param \Drupal\Core\Session\AccountInterface $account
* Run access checks for this account.
* @param \Symfony\Component\Routing\Route $route
* The route for which an access check is being done.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
public function access(AccountInterface $account, Route $route) {
$options = unserialize($route->getRequirement('var_options'));

$access_by_role = !empty(array_intersect(array_filter($options['role']), $account->getRoles()));
if ($access_by_role) {
$this->getlogger('ContactChecksumCheckAccess')->info('Access by role');
return AccessResult::allowed();
}
$request = $this->requestStack->getCurrentRequest();

$cid1 = filter_var($request->query->get('cid1'), FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]);
$checksum = $request->query->get('cs');

if (empty($cid1) || empty($checksum)) {
$this->getlogger('ContactChecksumCheckAccess')->info('No cid1 or cs param');
return AccessResult::forbidden();
}

// This forces a call to Civicrm initialize.
$this->civicrmApi->getFields('Contact');

$results = Contact::validateChecksum(FALSE)
->setContactId($cid1)
->setChecksum($checksum)
->execute();
return empty($results[0]['valid']) ? AccessResult::forbidden() : AccessResult::allowed();
}

}
28 changes: 27 additions & 1 deletion src/CiviEntityStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Utility\Error;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface;
use Drupal\field\FieldStorageConfigInterface;
use Psr\Log\LoggerInterface;

/**
* Defines entity class for external CiviCRM entities.
Expand Down Expand Up @@ -43,6 +45,13 @@ class CiviEntityStorage extends SqlContentEntityStorage {
*/
protected $entityFieldManager;

/**
* The Logger.
*
* @var \Psr\Log\LoggerInterface
*/
protected $logger;

/**
* Gets the CiviCRM API.
*
Expand All @@ -69,6 +78,19 @@ private function getConfigFactory() {
return $this->configFactory;
}

/**
* Gets the config factory.
*
* @return \Psr\Log\LoggerInterface
* The logger channel.
*/
private function getLogger() {
if (!$this->logger) {
$this->logger = \Drupal::logger('civicrm_entity');
}
return $this->logger;
}

/**
* Initializes table name variables.
*/
Expand Down Expand Up @@ -203,7 +225,7 @@ protected function doLoadMultiple(array $ids = NULL) {
}
}
catch (\Exception $e) {
watchdog_exception('civicrm_entity', $e);
Error::logException($this->getLogger(), $e);
}
}

Expand Down Expand Up @@ -394,6 +416,10 @@ protected function initFieldValues(ContentEntityInterface $entity, array $values
$civicrm_entity_settings = $this->getConfigFactory()->get('civicrm_entity.settings');
$field_definitions = $entity->getFieldDefinitions();
foreach ($field_definitions as $definition) {
if ($definition->getType() == 'metatag_computed') {
continue;
}

$items = $entity->get($definition->getName());
if ($items->isEmpty()) {
continue;
Expand Down
4 changes: 4 additions & 0 deletions src/Entity/CivicrmEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ public function civicrmApiNormalize() {
continue;
}

if ($storage_definition->getType() == 'metatag_computed') {
continue;
}

$main_property_name = $storage_definition->getMainPropertyName();
$list = [];
/** @var \Drupal\Core\Field\FieldItemInterface $item */
Expand Down
8 changes: 6 additions & 2 deletions src/Form/CivicrmEntitySettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Drupal\civicrm_entity\SupportedEntities;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
Expand Down Expand Up @@ -67,6 +68,8 @@ class CivicrmEntitySettings extends ConfigFormBase {
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
* @param \Drupal\Core\Config\TypedConfigManagerInterface $typedConfigManager
* The typed config manager.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Routing\RouteBuilderInterface $route_builder
Expand All @@ -80,8 +83,8 @@ class CivicrmEntitySettings extends ConfigFormBase {
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_render
* The render cache manager.
*/
public function __construct(ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, RouteBuilderInterface $route_builder, LocalActionManager $local_action_manager, LocalTaskManager $local_task_manager, MenuLinkManagerInterface $menu_link_manager, CacheBackendInterface $cache_render) {
parent::__construct($config_factory);
public function __construct(ConfigFactoryInterface $config_factory, TypedConfigManagerInterface $typedConfigManager, EntityTypeManagerInterface $entity_type_manager, RouteBuilderInterface $route_builder, LocalActionManager $local_action_manager, LocalTaskManager $local_task_manager, MenuLinkManagerInterface $menu_link_manager, CacheBackendInterface $cache_render) {
parent::__construct($config_factory, $typedConfigManager);
$this->entityTypeManager = $entity_type_manager;
$this->routeBuilder = $route_builder;
$this->localActionManager = $local_action_manager;
Expand All @@ -96,6 +99,7 @@ public function __construct(ConfigFactoryInterface $config_factory, EntityTypeMa
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
$container->get('config.typed'),
$container->get('entity_type.manager'),
$container->get('router.builder'),
$container->get('plugin.manager.menu.local_action'),
Expand Down
6 changes: 4 additions & 2 deletions src/ModuleInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Drupal\Core\Extension\ModuleInstaller as ExtensionModuleInstaller;
use Drupal\Core\Extension\ModuleInstallerInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Update\UpdateHookRegistry;

/**
Expand All @@ -24,8 +25,9 @@ class ModuleInstaller extends ExtensionModuleInstaller {
/**
* {@inheritdoc}
*/
public function __construct(ModuleInstallerInterface $module_installer, $root, ModuleHandlerInterface $module_handler, DrupalKernelInterface $kernel, Connection $connection, UpdateHookRegistry $update_registry) {
parent::__construct($root, $module_handler, $kernel, $connection, $update_registry);
public function __construct(ModuleInstallerInterface $module_installer, $root, ModuleHandlerInterface $module_handler, DrupalKernelInterface $kernel, Connection $connection, UpdateHookRegistry $update_registry, LoggerChannelFactoryInterface $logger_factory) {
$logger = $logger_factory->get('civicrm_entity');
parent::__construct($root, $module_handler, $kernel, $connection, $update_registry, $logger);
$this->moduleInstaller = $module_installer;
}

Expand Down
Loading

0 comments on commit dd553c6

Please sign in to comment.