From 4e08d5f4a009598349c471d474f8875f1327b7dc Mon Sep 17 00:00:00 2001 From: puresyntax71 <34715246+puresyntax71@users.noreply.github.com> Date: Thu, 9 Jan 2025 16:13:38 +0800 Subject: [PATCH 1/7] Add PHPCS. --- .github/workflows/phpcs.yml | 24 ++++++++++++++++++++++++ phpcs.xml.dist | 12 ++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 .github/workflows/phpcs.yml create mode 100644 phpcs.xml.dist diff --git a/.github/workflows/phpcs.yml b/.github/workflows/phpcs.yml new file mode 100644 index 00000000..2b6dd67f --- /dev/null +++ b/.github/workflows/phpcs.yml @@ -0,0 +1,24 @@ +name: Drupal coding standards + +on: pull_request + +jobs: + phpcs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@verbose + with: + php-version: 8.1 + coverage: none + tools: composer:v2, cs2pr, dealerdirect/phpcodesniffer-composer-installer:*, drupal/coder + - name: Get composer cache directory + id: composercache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + - uses: actions/cache@v2 + with: + path: ${{ steps.composercache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer- + - name: Detect coding standard violations + run: phpcs -q --report=checkstyle | cs2pr --graceful-warnings diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 00000000..91186fd9 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,12 @@ + + + PHP CodeSniffer configuration for CiviCRM entity. + . + + + */vendor/* + */node_modules/* + + + + From 2100ef3d5fee1c7dcfafd9c99c227df24df3547e Mon Sep 17 00:00:00 2001 From: puresyntax71 <34715246+puresyntax71@users.noreply.github.com> Date: Fri, 10 Jan 2025 16:42:58 +0800 Subject: [PATCH 2/7] Update PHP version. --- .github/workflows/phpcs.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/phpcs.yml b/.github/workflows/phpcs.yml index 2b6dd67f..45078d70 100644 --- a/.github/workflows/phpcs.yml +++ b/.github/workflows/phpcs.yml @@ -9,7 +9,7 @@ jobs: - uses: actions/checkout@v2 - uses: shivammathur/setup-php@verbose with: - php-version: 8.1 + php-version: 8.3 coverage: none tools: composer:v2, cs2pr, dealerdirect/phpcodesniffer-composer-installer:*, drupal/coder - name: Get composer cache directory @@ -21,4 +21,4 @@ jobs: key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} restore-keys: ${{ runner.os }}-composer- - name: Detect coding standard violations - run: phpcs -q --report=checkstyle | cs2pr --graceful-warnings + run: phpcs -q --report=checkstyle | cs2pr From cb983c4485512ef81bad0f622614dc2d0d3bf7b5 Mon Sep 17 00:00:00 2001 From: puresyntax71 <34715246+puresyntax71@users.noreply.github.com> Date: Fri, 10 Jan 2025 16:50:04 +0800 Subject: [PATCH 3/7] Automated fixes. --- civicrm_entity.module | 2 +- src/CiviEntityStorage.php | 9 ++++----- src/CivicrmEntityViewsData.php | 6 ++++-- src/Entity/CivicrmEntity.php | 3 +++ src/Plugin/Action/CivicrmContactAddToGroup.php | 2 +- .../FieldFormatter/ContactReferenceFormatter.php | 2 +- src/Plugin/Field/FieldFormatter/CustomMultiValue.php | 2 +- .../FieldFormatter/StateProvinceIsoFormatter.php | 2 +- src/Plugin/Field/FieldWidget/TextareaWidget.php | 2 +- src/Plugin/RulesAction/LoadLinkedUser.php | 2 +- src/Plugin/RulesAction/UserCreate.php | 12 ++++++------ src/Plugin/TypedDataFilter/FirstDotLastFilter.php | 2 +- src/Plugin/TypedDataFilter/FirstLastFilter.php | 2 +- src/Plugin/TypedDataFilter/InitialDotLastFilter.php | 2 +- src/Plugin/search_api/datasource/CivicrmEntity.php | 3 +++ src/Plugin/views/field/ActivityAttachments.php | 2 +- src/Plugin/views/field/CustomFile.php | 2 +- src/Plugin/views/filter/ContactReference.php | 2 +- src/Plugin/views/filter/InOperator.php | 8 +++++++- src/Plugin/views/filter/Proximity.php | 2 +- src/Plugin/views/query/CivicrmSql.php | 2 +- .../views/relationship/CiviCrmActivityContact.php | 2 +- src/Plugin/views/relationship/CiviCrmContactUser.php | 1 - .../views/relationship/EntityReverseLocation.php | 2 +- .../relationship/EntityReverseLocationPhone.php | 2 +- .../views/relationship/EntityReverseWebsiteType.php | 2 +- src/SupportedEntities.php | 4 ++-- src/TypedData/Options/CivicrmGroupOptions.php | 2 +- 28 files changed, 49 insertions(+), 37 deletions(-) diff --git a/civicrm_entity.module b/civicrm_entity.module index eaac3411..183da26b 100644 --- a/civicrm_entity.module +++ b/civicrm_entity.module @@ -365,7 +365,7 @@ function civicrm_entity_module_implements_alter(&$implementations, $hook) { * @return array * The array of field options. */ -function civicrm_entity_pseudoconstant_options(FieldStorageDefinitionInterface $definition, FieldableEntityInterface $entity = NULL, &$cacheable = NULL) { +function civicrm_entity_pseudoconstant_options(FieldStorageDefinitionInterface $definition, ?FieldableEntityInterface $entity = NULL, &$cacheable = NULL) { /** @var \Drupal\civicrm_entity\CiviCrmApiInterface $civicrm_api */ $civicrm_api = \Drupal::service('civicrm_entity.api'); $entity_type = \Drupal::entityTypeManager()->getDefinition($definition->getTargetEntityTypeId()); diff --git a/src/CiviEntityStorage.php b/src/CiviEntityStorage.php index fd703006..c69912f3 100644 --- a/src/CiviEntityStorage.php +++ b/src/CiviEntityStorage.php @@ -17,7 +17,6 @@ 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. @@ -78,7 +77,7 @@ private function getConfigFactory() { return $this->configFactory; } - /** + /** * Gets the config factory. * * @return \Psr\Log\LoggerInterface @@ -169,7 +168,7 @@ protected function doSave($id, EntityInterface $entity) { * * @throws \Drupal\Core\Entity\Sql\SqlContentEntityStorageException */ - protected function doLoadMultiple(array $ids = NULL) { + protected function doLoadMultiple(?array $ids = NULL) { $entities = []; if ($ids === NULL) { $civicrm_entity = $this->getCiviCrmApi()->get($this->entityType->get('civicrm_entity')); @@ -463,7 +462,7 @@ protected function initFieldValues(ContentEntityInterface $entity, array $values // Handle special cases for field definitions. foreach ($field_definitions as $definition) { - if (($field_metadata = $definition->getSetting('civicrm_entity_field_metadata')) && isset($field_metadata['custom_group_id']) && in_array($field_metadata['data_type'],['Float', 'Money'])) { + if (($field_metadata = $definition->getSetting('civicrm_entity_field_metadata')) && isset($field_metadata['custom_group_id']) && in_array($field_metadata['data_type'], ['Float', 'Money'])) { $items = $entity->get($definition->getName()); $item_values = $items->getValue(); if (!empty($item_values)) { @@ -502,7 +501,7 @@ protected function initFieldValues(ContentEntityInterface $entity, array $values /** * {@inheritdoc} */ - public function getTableMapping(array $storage_definitions = NULL) { + public function getTableMapping(?array $storage_definitions = NULL) { $table_mapping = $this->tableMapping; if ($table_mapping) { diff --git a/src/CivicrmEntityViewsData.php b/src/CivicrmEntityViewsData.php index 4fc66ce5..d4f3cf92 100644 --- a/src/CivicrmEntityViewsData.php +++ b/src/CivicrmEntityViewsData.php @@ -27,7 +27,7 @@ class CivicrmEntityViewsData extends EntityViewsData { /** * {@inheritdoc} */ - public function __construct(EntityTypeInterface $entity_type, SqlEntityStorageInterface $storage_controller, EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, TranslationInterface $translation_manager, EntityFieldManagerInterface $entity_field_manager = NULL, CiviCrmApiInterface $civicrm_api) { + public function __construct(EntityTypeInterface $entity_type, SqlEntityStorageInterface $storage_controller, EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, TranslationInterface $translation_manager, ?EntityFieldManagerInterface $entity_field_manager = NULL, CiviCrmApiInterface $civicrm_api) { parent::__construct($entity_type, $storage_controller, $entity_type_manager, $module_handler, $translation_manager, $entity_field_manager); $this->civicrmApi = $civicrm_api; $this->civicrmApi->civicrmInitialize(); @@ -495,13 +495,15 @@ protected function processViewsDataForSpecialFields(array &$views_field, $base_t } break; + case 'civicrm_website': if (isset($views_field['civicrm_contact']['reverse__civicrm_website__contact_id']['relationship'])) { $views_field['civicrm_contact']['reverse__civicrm_website__contact_id']['relationship']['id'] = 'civicrm_entity_reverse_website_type'; $views_field['civicrm_contact']['reverse__civicrm_website__contact_id']['relationship']['label'] = $this->t('Website'); } - + break; + case 'civicrm_address': if (isset($views_field['civicrm_contact']['reverse__civicrm_address__contact_id']['relationship'])) { $views_field['civicrm_contact']['reverse__civicrm_address__contact_id']['relationship']['id'] = 'civicrm_entity_reverse_location'; diff --git a/src/Entity/CivicrmEntity.php b/src/Entity/CivicrmEntity.php index 67e741e5..68085993 100644 --- a/src/Entity/CivicrmEntity.php +++ b/src/Entity/CivicrmEntity.php @@ -233,6 +233,9 @@ public function civicrmApiNormalize() { return $params; } + /** + * Get raw value. + */ public function getRawValue($field) { return $this->values[$field] ?? ''; } diff --git a/src/Plugin/Action/CivicrmContactAddToGroup.php b/src/Plugin/Action/CivicrmContactAddToGroup.php index 1a9aa815..1626dcd8 100644 --- a/src/Plugin/Action/CivicrmContactAddToGroup.php +++ b/src/Plugin/Action/CivicrmContactAddToGroup.php @@ -143,7 +143,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta /** * {@inheritdoc} */ - public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) { + public function access($object, ?AccountInterface $account = NULL, $return_as_object = FALSE) { return $object->access('update', $account, $return_as_object); } diff --git a/src/Plugin/Field/FieldFormatter/ContactReferenceFormatter.php b/src/Plugin/Field/FieldFormatter/ContactReferenceFormatter.php index 982a53a0..01c46ebd 100644 --- a/src/Plugin/Field/FieldFormatter/ContactReferenceFormatter.php +++ b/src/Plugin/Field/FieldFormatter/ContactReferenceFormatter.php @@ -33,7 +33,7 @@ class ContactReferenceFormatter extends EntityReferenceLabelFormatter { protected function checkAccess(EntityInterface $entity) { $permissions = [ 'view all contacts', - 'access all custom data' + 'access all custom data', ]; $account = User::load(\Drupal::currentUser()->id()); return AccessResult::allowedIfHasPermissions($account, $permissions, 'OR'); diff --git a/src/Plugin/Field/FieldFormatter/CustomMultiValue.php b/src/Plugin/Field/FieldFormatter/CustomMultiValue.php index 36c8bec5..aef1dc6f 100644 --- a/src/Plugin/Field/FieldFormatter/CustomMultiValue.php +++ b/src/Plugin/Field/FieldFormatter/CustomMultiValue.php @@ -31,7 +31,7 @@ field_types: [ "list_integer", "list_float", - "list_string" + "list_string", ] )] class CustomMultiValue extends OptionsDefaultFormatter { diff --git a/src/Plugin/Field/FieldFormatter/StateProvinceIsoFormatter.php b/src/Plugin/Field/FieldFormatter/StateProvinceIsoFormatter.php index d415a1d4..01ddfa9c 100644 --- a/src/Plugin/Field/FieldFormatter/StateProvinceIsoFormatter.php +++ b/src/Plugin/Field/FieldFormatter/StateProvinceIsoFormatter.php @@ -25,7 +25,7 @@ id: "civicrm_entity_state_province_iso", label: new TranslatableMarkup("State province ISO"), field_types: [ - "list_integer" + "list_integer", ] )] class StateProvinceIsoFormatter extends FormatterBase { diff --git a/src/Plugin/Field/FieldWidget/TextareaWidget.php b/src/Plugin/Field/FieldWidget/TextareaWidget.php index 59836887..9ff602b7 100644 --- a/src/Plugin/Field/FieldWidget/TextareaWidget.php +++ b/src/Plugin/Field/FieldWidget/TextareaWidget.php @@ -24,7 +24,7 @@ id: "civicrm_entity_textarea", label: new TranslatableMarkup("Text area (multiple rows, default CiviCRM format 1)"), field_types: [ - "text_long" + "text_long", ] )] class TextareaWidget extends CoreTextareaWidget { diff --git a/src/Plugin/RulesAction/LoadLinkedUser.php b/src/Plugin/RulesAction/LoadLinkedUser.php index 2a598eda..2da313ec 100644 --- a/src/Plugin/RulesAction/LoadLinkedUser.php +++ b/src/Plugin/RulesAction/LoadLinkedUser.php @@ -48,7 +48,7 @@ "user_fetched" => new ContextDefinition( data_type: "entity:user", label: new TranslatableMarkup("Fetched user"), - ) + ), ] )] class LoadLinkedUser extends RulesActionBase implements ContainerFactoryPluginInterface { diff --git a/src/Plugin/RulesAction/UserCreate.php b/src/Plugin/RulesAction/UserCreate.php index c277c8e5..6634dc5a 100644 --- a/src/Plugin/RulesAction/UserCreate.php +++ b/src/Plugin/RulesAction/UserCreate.php @@ -69,7 +69,7 @@ label: new TranslatableMarkup("CiviCRM contact ID"), description: new TranslatableMarkup("The CiviCRM contact ID."), required: TRUE - ), + ), "is_active" => new ContextDefinition( data_type: "boolean", label: new TranslatableMarkup("Activate account"), @@ -77,7 +77,7 @@ assignment_restriction: "input", default_value: "TRUE", required: FALSE - ), + ), "notify" => new ContextDefinition( data_type: "boolean", label: new TranslatableMarkup("Send account notification email"), @@ -85,7 +85,7 @@ assignment_restriction: "input", default_value: FALSE, required: FALSE - ), + ), "signin" => new ContextDefinition( data_type: "boolean", label: new TranslatableMarkup("Instant signin"), @@ -93,18 +93,18 @@ assignment_restriction: "input", default_value: FALSE, required: FALSE - ), + ), "format" => new ContextDefinition( data_type: "string", label: new TranslatableMarkup("Format"), description: new TranslatableMarkup("Format of the username.") - ) + ), ], provides: [ "user_fetched" => new ContextDefinition( data_type: "entity:user", label: new TranslatableMarkup("Created Drupal user"), - ) + ), ] )] class UserCreate extends RulesActionBase implements ContainerFactoryPluginInterface { diff --git a/src/Plugin/TypedDataFilter/FirstDotLastFilter.php b/src/Plugin/TypedDataFilter/FirstDotLastFilter.php index a9a84643..c391f5dd 100644 --- a/src/Plugin/TypedDataFilter/FirstDotLastFilter.php +++ b/src/Plugin/TypedDataFilter/FirstDotLastFilter.php @@ -46,7 +46,7 @@ public function filtersTo(DataDefinitionInterface $definition, array $arguments) /** * {@inheritdoc} */ - public function filter(DataDefinitionInterface $definition, $value, array $arguments, BubbleableMetadata $bubbleable_metadata = NULL) { + public function filter(DataDefinitionInterface $definition, $value, array $arguments, ?BubbleableMetadata $bubbleable_metadata = NULL) { $login = str_replace(' ', '', strtolower($value->get('first_name')->getString())) . '.' . strtolower($value->get('last_name')->getString()); return filter_var($login, FILTER_SANITIZE_EMAIL); diff --git a/src/Plugin/TypedDataFilter/FirstLastFilter.php b/src/Plugin/TypedDataFilter/FirstLastFilter.php index 5639897b..c2c02b5b 100644 --- a/src/Plugin/TypedDataFilter/FirstLastFilter.php +++ b/src/Plugin/TypedDataFilter/FirstLastFilter.php @@ -45,7 +45,7 @@ public function filtersTo(DataDefinitionInterface $definition, array $arguments) /** * {@inheritdoc} */ - public function filter(DataDefinitionInterface $definition, $value, array $arguments, BubbleableMetadata $bubbleable_metadata = NULL) { + public function filter(DataDefinitionInterface $definition, $value, array $arguments, ?BubbleableMetadata $bubbleable_metadata = NULL) { $login = str_replace(' ', '', ucfirst(strtolower($value->get('first_name')->getString()))) . ucfirst(strtolower($value->get('last_name')->getString())); return filter_var($login, FILTER_SANITIZE_EMAIL); diff --git a/src/Plugin/TypedDataFilter/InitialDotLastFilter.php b/src/Plugin/TypedDataFilter/InitialDotLastFilter.php index 9989a4aa..06cd8e16 100644 --- a/src/Plugin/TypedDataFilter/InitialDotLastFilter.php +++ b/src/Plugin/TypedDataFilter/InitialDotLastFilter.php @@ -45,7 +45,7 @@ public function filtersTo(DataDefinitionInterface $definition, array $arguments) /** * {@inheritdoc} */ - public function filter(DataDefinitionInterface $definition, $value, array $arguments, BubbleableMetadata $bubbleable_metadata = NULL) { + public function filter(DataDefinitionInterface $definition, $value, array $arguments, ?BubbleableMetadata $bubbleable_metadata = NULL) { $c = preg_match_all("/(?<=\b)[a-z]/i", ($value->get('first_name')->getString()), $m); if ($c > 0) { $login = strtolower(implode('', $m[0])) . '.' . strtolower($value->get('last_name')->getString()); diff --git a/src/Plugin/search_api/datasource/CivicrmEntity.php b/src/Plugin/search_api/datasource/CivicrmEntity.php index 8116758d..e9a82b14 100644 --- a/src/Plugin/search_api/datasource/CivicrmEntity.php +++ b/src/Plugin/search_api/datasource/CivicrmEntity.php @@ -6,6 +6,9 @@ use Drupal\search_api\Plugin\search_api\datasource\ContentEntity; use Symfony\Component\DependencyInjection\ContainerInterface; +/** + * Datasource for CiviCRM entity. + */ class CivicrmEntity extends ContentEntity { /** diff --git a/src/Plugin/views/field/ActivityAttachments.php b/src/Plugin/views/field/ActivityAttachments.php index 5c2f9978..ad258aa3 100644 --- a/src/Plugin/views/field/ActivityAttachments.php +++ b/src/Plugin/views/field/ActivityAttachments.php @@ -45,7 +45,7 @@ public function __construct(array $configuration, $plugin_id, array $plugin_defi /** * {@inheritdoc} */ - public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { + public function init(ViewExecutable $view, DisplayPluginBase $display, ?array &$options = NULL) { parent::init($view, $display, $options); $this->civicrmApi->civicrmInitialize(); } diff --git a/src/Plugin/views/field/CustomFile.php b/src/Plugin/views/field/CustomFile.php index aceff7c4..a4dc0b15 100644 --- a/src/Plugin/views/field/CustomFile.php +++ b/src/Plugin/views/field/CustomFile.php @@ -46,7 +46,7 @@ public function __construct(array $configuration, $plugin_id, array $plugin_defi /** * {@inheritdoc} */ - public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { + public function init(ViewExecutable $view, DisplayPluginBase $display, ?array &$options = NULL) { parent::init($view, $display, $options); $this->civicrmApi->civicrmInitialize(); $this->additional_fields['entity_id'] = 'entity_id'; diff --git a/src/Plugin/views/filter/ContactReference.php b/src/Plugin/views/filter/ContactReference.php index ae21e519..23686b5c 100644 --- a/src/Plugin/views/filter/ContactReference.php +++ b/src/Plugin/views/filter/ContactReference.php @@ -109,7 +109,7 @@ public function acceptExposedInput($input) { /** * {@inheritdoc} */ - public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { + public function init(ViewExecutable $view, DisplayPluginBase $display, ?array &$options = NULL) { parent::init($view, $display, $options); $this->civicrmApi->civicrmInitialize(); } diff --git a/src/Plugin/views/filter/InOperator.php b/src/Plugin/views/filter/InOperator.php index 5066a3dd..a7007e10 100644 --- a/src/Plugin/views/filter/InOperator.php +++ b/src/Plugin/views/filter/InOperator.php @@ -47,7 +47,7 @@ public function __construct(array $configuration, $plugin_id, array $plugin_defi /** * {@inheritdoc} */ - public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { + public function init(ViewExecutable $view, DisplayPluginBase $display, ?array &$options = NULL) { parent::init($view, $display, $options); $this->civicrmApi->civicrmInitialize(); } @@ -140,6 +140,9 @@ protected function opSimple() { } } + /** + * {@inheritdoc} + */ public function operators() { $operators = parent::operators(); if (!empty($this->definition['allow empty'])) { @@ -161,6 +164,9 @@ public function operators() { return $operators; } + /** + * Operation for empty string. + */ protected function opEmptyString() { $this->ensureMyTable(); $field = "$this->tableAlias.$this->realField"; diff --git a/src/Plugin/views/filter/Proximity.php b/src/Plugin/views/filter/Proximity.php index bbdde469..abd2404a 100644 --- a/src/Plugin/views/filter/Proximity.php +++ b/src/Plugin/views/filter/Proximity.php @@ -52,7 +52,7 @@ public static function create(ContainerInterface $container, array $configuratio /** * {@inheritdoc} */ - public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { + public function init(ViewExecutable $view, DisplayPluginBase $display, ?array &$options = NULL) { parent::init($view, $display, $options); $this->civicrmApi->civicrmInitialize(); \CRM_Contact_BAO_ProximityQuery::initialize(); diff --git a/src/Plugin/views/query/CivicrmSql.php b/src/Plugin/views/query/CivicrmSql.php index e374be84..a893efee 100644 --- a/src/Plugin/views/query/CivicrmSql.php +++ b/src/Plugin/views/query/CivicrmSql.php @@ -62,7 +62,7 @@ public static function create(ContainerInterface $container, array $configuratio /** * {@inheritdoc} */ - public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { + public function init(ViewExecutable $view, DisplayPluginBase $display, ?array &$options = NULL) { // Ensure that Drupal is aware of the CiviCRM database connection. // This should be added into the settings.php, but we provide a backwards // compatibility layer here. diff --git a/src/Plugin/views/relationship/CiviCrmActivityContact.php b/src/Plugin/views/relationship/CiviCrmActivityContact.php index 91024be8..fa6da5ba 100644 --- a/src/Plugin/views/relationship/CiviCrmActivityContact.php +++ b/src/Plugin/views/relationship/CiviCrmActivityContact.php @@ -66,7 +66,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { + public function init(ViewExecutable $view, DisplayPluginBase $display, ?array &$options = NULL) { parent::init($view, $display, $options); $this->definition['extra'] = []; diff --git a/src/Plugin/views/relationship/CiviCrmContactUser.php b/src/Plugin/views/relationship/CiviCrmContactUser.php index 455a9474..d383cd8a 100644 --- a/src/Plugin/views/relationship/CiviCrmContactUser.php +++ b/src/Plugin/views/relationship/CiviCrmContactUser.php @@ -6,7 +6,6 @@ use Drupal\Core\Utility\Error; use Drupal\views\Attribute\ViewsRelationship; use Symfony\Component\DependencyInjection\ContainerInterface; -use Psr\Log\LoggerInterface; /** * Relationship for referencing civicrm_contact and user. diff --git a/src/Plugin/views/relationship/EntityReverseLocation.php b/src/Plugin/views/relationship/EntityReverseLocation.php index 162177d1..50df4e48 100644 --- a/src/Plugin/views/relationship/EntityReverseLocation.php +++ b/src/Plugin/views/relationship/EntityReverseLocation.php @@ -65,7 +65,7 @@ public static function create(ContainerInterface $container, array $configuratio /** * {@inheritdoc} */ - public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { + public function init(ViewExecutable $view, DisplayPluginBase $display, ?array &$options = NULL) { parent::init($view, $display, $options); $this->civicrmApi->civicrmInitialize(); diff --git a/src/Plugin/views/relationship/EntityReverseLocationPhone.php b/src/Plugin/views/relationship/EntityReverseLocationPhone.php index e4085bba..73ba530d 100644 --- a/src/Plugin/views/relationship/EntityReverseLocationPhone.php +++ b/src/Plugin/views/relationship/EntityReverseLocationPhone.php @@ -27,7 +27,7 @@ class EntityReverseLocationPhone extends EntityReverseLocation { /** * {@inheritdoc} */ - public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { + public function init(ViewExecutable $view, DisplayPluginBase $display, ?array &$options = NULL) { parent::init($view, $display, $options); $this->phoneTypes = \CRM_Core_BAO_Phone::buildOptions('phone_type_id'); diff --git a/src/Plugin/views/relationship/EntityReverseWebsiteType.php b/src/Plugin/views/relationship/EntityReverseWebsiteType.php index 3e8a7668..43282b3c 100644 --- a/src/Plugin/views/relationship/EntityReverseWebsiteType.php +++ b/src/Plugin/views/relationship/EntityReverseWebsiteType.php @@ -65,7 +65,7 @@ public static function create(ContainerInterface $container, array $configuratio /** * {@inheritdoc} */ - public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { + public function init(ViewExecutable $view, DisplayPluginBase $display, ?array &$options = NULL) { parent::init($view, $display, $options); $this->civicrmApi->civicrmInitialize(); $this->websiteTypes = \CRM_Core_BAO_Website::buildOptions('website_type_id'); diff --git a/src/SupportedEntities.php b/src/SupportedEntities.php index 99f8dc4c..c7e195a9 100644 --- a/src/SupportedEntities.php +++ b/src/SupportedEntities.php @@ -740,7 +740,7 @@ public static function getInfo() { if (!in_array($entity_info['civicrm entity name'], $api_entity_types)) { unset($civicrm_entity_info[$entity_type]); } - // Insert dblocale table names + // Insert dblocale table names. $multilingual = \CRM_Core_I18n::isMultilingual(); if ($multilingual) { // @codingStandardsIgnoreStart @@ -915,7 +915,7 @@ public static function alterEntityInfo(array &$civicrm_entity_info) { \Drupal::service('civicrm_entity.api')->civicrmInitialize(); if (!Container::isContainerBooted()) { - return FALSE; + return FALSE; } $code_version = explode('.', \CRM_Utils_System::version()); diff --git a/src/TypedData/Options/CivicrmGroupOptions.php b/src/TypedData/Options/CivicrmGroupOptions.php index 80faac5e..4648dc43 100644 --- a/src/TypedData/Options/CivicrmGroupOptions.php +++ b/src/TypedData/Options/CivicrmGroupOptions.php @@ -41,7 +41,7 @@ public static function create(ContainerInterface $container) { /** * {@inheritdoc} */ - public function getPossibleOptions(AccountInterface $account = NULL) { + public function getPossibleOptions(?AccountInterface $account = NULL) { $options = []; // Load all the node types. From f3c891c071e25cd4715128caec363f070164df60 Mon Sep 17 00:00:00 2001 From: puresyntax71 <34715246+puresyntax71@users.noreply.github.com> Date: Fri, 10 Jan 2025 16:51:28 +0800 Subject: [PATCH 4/7] Manual fixes. --- src/CiviEntityStorage.php | 3 ++- src/Entity/Sql/CivicrmEntityStorageSchema.php | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CiviEntityStorage.php b/src/CiviEntityStorage.php index c69912f3..5cdc4429 100644 --- a/src/CiviEntityStorage.php +++ b/src/CiviEntityStorage.php @@ -462,7 +462,8 @@ protected function initFieldValues(ContentEntityInterface $entity, array $values // Handle special cases for field definitions. foreach ($field_definitions as $definition) { - if (($field_metadata = $definition->getSetting('civicrm_entity_field_metadata')) && isset($field_metadata['custom_group_id']) && in_array($field_metadata['data_type'], ['Float', 'Money'])) { + $data_types = ['Float', 'Money']; + if (($field_metadata = $definition->getSetting('civicrm_entity_field_metadata')) && isset($field_metadata['custom_group_id']) && in_array($field_metadata['data_type'], $data_types)) { $items = $entity->get($definition->getName()); $item_values = $items->getValue(); if (!empty($item_values)) { diff --git a/src/Entity/Sql/CivicrmEntityStorageSchema.php b/src/Entity/Sql/CivicrmEntityStorageSchema.php index 2f42e4a0..4be9f402 100644 --- a/src/Entity/Sql/CivicrmEntityStorageSchema.php +++ b/src/Entity/Sql/CivicrmEntityStorageSchema.php @@ -54,7 +54,6 @@ public function requiresFieldStorageSchemaChanges(FieldStorageDefinitionInterfac * {@inheritdoc} */ public function onFieldableEntityTypeCreate(EntityTypeInterface $entity_type, array $field_storage_definitions) { - return; } } From c10cb01c3e8de1a4cde91fe85aaf0c1225f8ec3d Mon Sep 17 00:00:00 2001 From: puresyntax71 <34715246+puresyntax71@users.noreply.github.com> Date: Fri, 10 Jan 2025 16:55:47 +0800 Subject: [PATCH 5/7] Minor fix. --- src/Plugin/views/field/CustomEntityField.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Plugin/views/field/CustomEntityField.php b/src/Plugin/views/field/CustomEntityField.php index 70409f0c..3776d083 100644 --- a/src/Plugin/views/field/CustomEntityField.php +++ b/src/Plugin/views/field/CustomEntityField.php @@ -65,7 +65,7 @@ class CustomEntityField extends EntityField { /** * {@inheritdoc} */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, FormatterPluginManager $formatter_plugin_manager, FieldTypePluginManagerInterface $field_type_plugin_manager, LanguageManagerInterface $language_manager, RendererInterface $renderer, EntityRepositoryInterface $entity_repository = NULL, EntityFieldManagerInterface $entity_field_manager = NULL, EntityTypeBundleInfoInterface $entity_type_bundle_info, CiviCrmApiInterface $civicrm_api) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, FormatterPluginManager $formatter_plugin_manager, FieldTypePluginManagerInterface $field_type_plugin_manager, LanguageManagerInterface $language_manager, RendererInterface $renderer, ?EntityRepositoryInterface $entity_repository = NULL, ?EntityFieldManagerInterface $entity_field_manager = NULL, EntityTypeBundleInfoInterface $entity_type_bundle_info, CiviCrmApiInterface $civicrm_api) { parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type_manager, $formatter_plugin_manager, $field_type_plugin_manager, $language_manager, $renderer, $entity_repository, $entity_field_manager, $entity_type_bundle_info); $this->civicrmApi = $civicrm_api; } @@ -93,7 +93,7 @@ public static function create(ContainerInterface $container, array $configuratio /** * {@inheritdoc} */ - public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { + public function init(ViewExecutable $view, DisplayPluginBase $display, ?array &$options = NULL) { $field_definition = $this->getFieldDefinition(); if ($settings = $field_definition->getSetting('civicrm_entity_field_metadata')) { From 11727cce2932d9aca96ac05877c14fae926a8c60 Mon Sep 17 00:00:00 2001 From: puresyntax71 <34715246+puresyntax71@users.noreply.github.com> Date: Fri, 10 Jan 2025 16:58:18 +0800 Subject: [PATCH 6/7] Remove DrupalPractice. --- phpcs.xml.dist | 1 - 1 file changed, 1 deletion(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 91186fd9..654cc75f 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -8,5 +8,4 @@ */node_modules/* - From efbf25cee919c7b89990b2556f85875fd81028d8 Mon Sep 17 00:00:00 2001 From: puresyntax71 <34715246+puresyntax71@users.noreply.github.com> Date: Fri, 10 Jan 2025 17:59:54 +0800 Subject: [PATCH 7/7] Minor update. --- src/CivicrmEntityViewsData.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CivicrmEntityViewsData.php b/src/CivicrmEntityViewsData.php index d4f3cf92..1ec0817a 100644 --- a/src/CivicrmEntityViewsData.php +++ b/src/CivicrmEntityViewsData.php @@ -27,7 +27,7 @@ class CivicrmEntityViewsData extends EntityViewsData { /** * {@inheritdoc} */ - public function __construct(EntityTypeInterface $entity_type, SqlEntityStorageInterface $storage_controller, EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, TranslationInterface $translation_manager, ?EntityFieldManagerInterface $entity_field_manager = NULL, CiviCrmApiInterface $civicrm_api) { + public function __construct(EntityTypeInterface $entity_type, SqlEntityStorageInterface $storage_controller, EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, TranslationInterface $translation_manager, EntityFieldManagerInterface $entity_field_manager, CiviCrmApiInterface $civicrm_api) { parent::__construct($entity_type, $storage_controller, $entity_type_manager, $module_handler, $translation_manager, $entity_field_manager); $this->civicrmApi = $civicrm_api; $this->civicrmApi->civicrmInitialize();