Skip to content
Snippets Groups Projects
Commit 05ad6de2 authored by Alberto Paderno's avatar Alberto Paderno Committed by Marcos Cano
Browse files

Issue #3445394 by arunsahijpal, avpaderno, alexpott, kul.pratap, chandansha,...

Issue #3445394 by arunsahijpal, avpaderno, alexpott, kul.pratap, chandansha, cleavinjosh, marcoscano: Fix the PHP_CodeSniffer issues reported by GitLab CI
parent d19d0969
Branches
Tags
1 merge request!82Issue #3445394: Fix the PHP_CodeSniffer issues reported by GitLab CI
Pipeline #391237 failed
Showing
with 71 additions and 56 deletions
......@@ -11,7 +11,8 @@ variables:
OPT_IN_TEST_PREVIOUS_MINOR: 1
OPT_IN_TEST_PREVIOUS_MAJOR: 1
RUN_JOB_UPGRADE_STATUS: '1'
phpcs:
allow_failure: false
# By default, Gitlab CI runs on the default system mysql database, change
# this as it won't work for the schema required by entity_usage.
# Remove when https://www.drupal.org/project/gitlab_templates/issues/3463044 is
......
......@@ -257,7 +257,7 @@ function entity_usage_update_8204(&$sandbox) {
$schema->addIndex(
'entity_usage',
'source_entity',
['source_type','source_id'],
['source_type', 'source_id'],
$spec
);
}
......@@ -265,7 +265,7 @@ function entity_usage_update_8204(&$sandbox) {
$schema->addIndex(
'entity_usage',
'source_entity_string',
['source_type','source_id_string'],
['source_type', 'source_id_string'],
$spec
);
}
......
......@@ -110,12 +110,14 @@ function entity_usage_form_alter(&$form, FormStateInterface $form_state, $form_i
$form['entity_usage_edit_warning'] = [
'#theme' => 'status_messages',
'#message_list' => [
'warning' => [t('Modifications on this form will affect all <a href="@usage_url" target="_blank">existing usages</a> of this entity.', [
'@usage_url' => Url::fromRoute('entity_usage.usage_list', [
'entity_type' => $entity->getEntityTypeId(),
'entity_id' => $entity->id(),
])->toString(),
])],
'warning' => [
t('Modifications on this form will affect all <a href="@usage_url" target="_blank">existing usages</a> of this entity.', [
'@usage_url' => Url::fromRoute('entity_usage.usage_list', [
'entity_type' => $entity->getEntityTypeId(),
'entity_id' => $entity->id(),
])->toString(),
]),
],
],
'#status_headings' => ['warning' => t('Warning message')],
'#weight' => -201,
......@@ -143,7 +145,7 @@ function entity_usage_form_alter(&$form, FormStateInterface $form_state, $form_i
'entity_type' => $entity->getEntityTypeId(),
'entity_id' => $entity->id(),
])->toString(),
])
]),
],
],
'#status_headings' => ['warning' => t('Warning message')],
......
......@@ -2,15 +2,16 @@
/**
* @file
* hook_post_update_NAME functions for entity_usage module.
* Post update functions for the Entity Usage module.
*/
use Drupal\Core\Entity\RevisionableStorageInterface;
use Drupal\Core\Url;
use Drupal\Core\Site\Settings;
use Drupal\Core\Url;
/**
* Implements hook_post_update_NAME().
*
* Re-generate entity_usage statistics.
*/
function entity_usage_post_update_regenerate_2x(&$sandbox) {
......
......@@ -4,9 +4,9 @@ namespace Drupal\entity_usage\Commands;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\entity_usage\EntityUsageBatchManager;
use Drupal\entity_usage\EntityUsageQueueBatchManager;
use Drush\Commands\DrushCommands;
use Drupal\entity_usage\EntityUsageBatchManager;
/**
* Entity Usage drush commands.
......
......@@ -2,7 +2,6 @@
namespace Drupal\entity_usage\Controller;
use Drupal\block_content\BlockContentInterface;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Controller\ControllerBase;
......@@ -13,6 +12,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\RevisionableInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Pager\PagerManagerInterface;
use Drupal\block_content\BlockContentInterface;
use Drupal\entity_usage\EntityUsageInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -100,7 +100,7 @@ class ListUsageController extends ControllerBase {
* @param \Drupal\entity_usage\EntityUsageInterface $entity_usage
* The EntityUsage service.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory service.
* The config factory service.
* @param \Drupal\Core\Pager\PagerManagerInterface $pager_manager
* The pager manager.
*/
......@@ -143,7 +143,10 @@ class ListUsageController extends ControllerBase {
$all_rows = $this->getRows($entity_type, $entity_id);
if (empty($all_rows)) {
return [
'#markup' => $this->t('There are no recorded usages for entity of type: @type with id: @id', ['@type' => $entity_type, '@id' => $entity_id]),
'#markup' => $this->t(
'There are no recorded usages for entity of type: @type with id: @id',
['@type' => $entity_type, '@id' => $entity_id]
),
];
}
......
......@@ -7,7 +7,7 @@ use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\TranslatableInterface;
/**
* Class EntityUpdateManager.
* The entity update manager.
*
* @package Drupal\entity_usage
*/
......@@ -35,7 +35,7 @@ class EntityUpdateManager implements EntityUpdateManagerInterface {
protected $config;
/**
* EntityUpdateManager constructor.
* Constructs a new \Drupal\entity_usage\EntityUpdateManager object.
*
* @param \Drupal\entity_usage\EntityUsageInterface $usage_service
* The usage tracking service.
......@@ -140,7 +140,7 @@ class EntityUpdateManager implements EntityUpdateManagerInterface {
}
/**
* Check if an entity is allowed to be tracked as source.
* Checks if an entity is allowed to be tracked as source.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity object.
......@@ -163,7 +163,7 @@ class EntityUpdateManager implements EntityUpdateManagerInterface {
}
/**
* Get the enabled tracking plugins, all plugins are enabled by default.
* Gets the enabled tracking plugins, all plugins are enabled by default.
*
* @return array<string, \Drupal\entity_usage\EntityUsageTrackInterface>
* The enabled plugin instances keyed by plugin ID.
......
......@@ -5,14 +5,14 @@ namespace Drupal\entity_usage;
use Drupal\Core\Entity\EntityInterface;
/**
* Class EntityUpdateManagerInterface.
* The interface implemented by the entity update manager.
*
* @package Drupal\entity_usage
*/
interface EntityUpdateManagerInterface {
/**
* Track updates on creation of potential source entities.
* Tracks updates on creation of potential source entities.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity we are dealing with.
......@@ -20,7 +20,7 @@ interface EntityUpdateManagerInterface {
public function trackUpdateOnCreation(EntityInterface $entity);
/**
* Track updates on edit / update of potential source entities.
* Tracks updates on edits/updates of potential source entities.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity we are dealing with.
......@@ -28,7 +28,7 @@ interface EntityUpdateManagerInterface {
public function trackUpdateOnEdition(EntityInterface $entity);
/**
* Track updates on deletion of entities.
* Tracks updates on deletion of entities.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity we are dealing with.
......
......@@ -280,8 +280,6 @@ class EntityUsage implements EntityUsageInterface {
* Core doesn't support big integers (bigint) for entity reference fields.
* Therefore we consider integers with more than 10 digits (big integer) to be
* strings.
* @todo: Fix bigint support once fixed in core. More info on #2680571 and
* #2989033.
*
* @param int|string $value
* The value to check.
......@@ -289,6 +287,9 @@ class EntityUsage implements EntityUsageInterface {
* @return bool
* TRUE if the value is a numeric integer or a string containing an integer,
* FALSE otherwise.
*
* @todo Fix bigint support once fixed in core. More info on #2680571 and
* #2989033.
*/
protected function isInt($value) {
return ((string) (int) $value === (string) $value) && strlen($value) < 11;
......
......@@ -39,15 +39,15 @@ class EntityUsageBatchManager implements LoggerAwareInterface {
/**
* Recreate the entity usage statistics.
*
* @param bool $keep_existing_records
* (optional) If TRUE existing usage records won't be deleted. Defaults to
* FALSE.
*
* Generate a batch to recreate the statistics for all entities.
* Note that if we force all statistics to be created, there is no need to
* separate them between source / target cases. If all entities are
* going to be re-tracked, tracking all of them as source is enough, because
* there could never be a target without a source.
* separate them between source/target cases. If all entities are going to
* be re-tracked, tracking all of them as source is enough, because there
* could never be a target without a source.
*
* @param bool $keep_existing_records
* (optional) If TRUE, existing usage records won't be deleted. Defaults to
* FALSE.
*/
public function recreate($keep_existing_records = FALSE) {
$batch = $this->generateBatch($keep_existing_records);
......@@ -83,7 +83,10 @@ class EntityUsageBatchManager implements LoggerAwareInterface {
$track_this_entity_type = TRUE;
}
if ($track_this_entity_type) {
$operations[] = ['\Drupal\entity_usage\EntityUsageBatchManager::updateSourcesBatchWorker', [$entity_type_id, $keep_existing_records]];
$operations[] = [
'\Drupal\entity_usage\EntityUsageBatchManager::updateSourcesBatchWorker',
[$entity_type_id, $keep_existing_records],
];
}
}
......@@ -123,7 +126,7 @@ class EntityUsageBatchManager implements LoggerAwareInterface {
$context['sandbox']['progress'] = 0;
$context['sandbox']['current_id'] = '';
if (($id_definition instanceof FieldStorageDefinitionInterface) && $id_definition->getType() === 'integer') {
if (($id_definition instanceof FieldStorageDefinitionInterface) && $id_definition->getType() === 'integer') {
$context['sandbox']['current_id'] = -1;
}
$context['sandbox']['total'] = (int) $entity_storage->getQuery()
......
......@@ -160,7 +160,8 @@ interface EntityUsageInterface {
* @param \Drupal\Core\Entity\EntityInterface $source_entity
* The source entity to check for references.
* @param int $vid
* (optional) The revision id to return the references for. Defaults to all revisions.
* (optional) The revision id to return the references for.
* Defaults to all revisions.
*
* @return array<string, array<int, array<array{method: string, field_name: string, count: string}>>>
* A nested array with usage data. The first level is keyed by the type of
......@@ -194,8 +195,10 @@ interface EntityUsageInterface {
* Note that if $include_method is TRUE, the first level is keyed by the
* reference method, and the second level will continue as explained above.
*
* @deprecated in branch 2.x.
* @deprecated in entity_usage:2.0.0 and is removed from entity_usage:3.0.0.
* Use \Drupal\entity_usage\EntityUsageInterface::listSources() instead.
*
* @see https://www.drupal.org/project/entity_usage/issues/3445394
*/
public function listUsage(EntityInterface $entity, $include_method = FALSE);
......@@ -216,8 +219,10 @@ interface EntityUsageInterface {
* the second level contains the usage count, which will be summed for all
* revisions and translations tracked.
*
* @deprecated in branch 2.x.
* @deprecated in entity_usage:2.0.0 and is removed from entity_usage:3.0.0.
* Use \Drupal\entity_usage\EntityUsageInterface::listTargets() instead.
*
* @see https://www.drupal.org/project/entity_usage/issues/3445394
*/
public function listReferencedEntities(EntityInterface $entity);
......
......@@ -2,8 +2,6 @@
namespace Drupal\entity_usage;
use Drupal\Core\StreamWrapper\StreamWrapperInterface;
use Drupal\Core\Url;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityInterface;
......@@ -14,7 +12,8 @@ use Drupal\Core\Entity\RevisionableInterface;
use Drupal\Core\Path\PathValidatorInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\PluginBase;
use Drupal\Core\StreamWrapper\PublicStream;
use Drupal\Core\StreamWrapper\StreamWrapperInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -56,7 +55,7 @@ abstract class EntityUsageTrackBase extends PluginBase implements EntityUsageTra
* @var \Drupal\Core\Entity\EntityRepositoryInterface
*/
protected $entityRepository;
/**
* The Drupal Path Validator service.
*
......@@ -272,7 +271,7 @@ abstract class EntityUsageTrackBase extends PluginBase implements EntityUsageTra
return $referencing_fields_on_bundle;
}
/**
* Process the url to a Url object.
*
......
......@@ -2,9 +2,9 @@
namespace Drupal\entity_usage\Form;
use Drupal\entity_usage\EntityUsageBatchManager;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\entity_usage\EntityUsageBatchManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......
......@@ -233,12 +233,12 @@ class EntityUsageSettingsForm extends ConfigFormBase {
$form['edit_warning_message_entity_types']['entity_types'][$entity_type_id]['#states'] = [
'enabled' => [
':input[name="track_enabled_target_entity_types[entity_types][' . $entity_type_id . ']"]' => ['checked' => TRUE],
]
],
];
$form['delete_warning_message_entity_types']['entity_types'][$entity_type_id]['#states'] = [
'enabled' => [
':input[name="track_enabled_target_entity_types[entity_types][' . $entity_type_id . ']"]' => ['checked' => TRUE],
]
],
];
}
......
......@@ -2,9 +2,9 @@
namespace Drupal\entity_usage\Plugin\EntityUsage\Track;
use Drupal\block_content\Plugin\Block\BlockContentBlock;
use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\block_content\Plugin\Block\BlockContentBlock;
use Drupal\entity_usage\EntityUsageTrackBase;
/**
......@@ -34,7 +34,7 @@ class BlockField extends EntityUsageTrackBase {
// If there is a view inside this block, track the view entity instead.
if ($block_instance->getBaseId() === 'views_block') {
list($view_name, $display_id) = explode('-', $block_instance->getDerivativeId(), 2);
[$view_name, $display_id] = explode('-', $block_instance->getDerivativeId(), 2);
// @todo worth trying to track the display id as well?
// At this point the view is supposed to exist. Only track it if so.
if ($this->entityTypeManager->getStorage('view')->load($view_name)) {
......
......@@ -37,7 +37,7 @@ class CkeditorImage extends TextFieldEmbedBase {
// when we should record 2. The alternative is to add a lot of complexity
// to the update logic of our plugin, to deal with all possible
// combinations in the update scenario.
// @TODO Re-evaluate if this is worth the effort and overhead.
// @todo Re-evaluate if this is worth the effort and overhead.
$entities[$node->getAttribute('data-entity-uuid')] = $node->getAttribute('data-entity-type');
}
return $entities;
......
......@@ -36,7 +36,7 @@ class EntityEmbed extends TextFieldEmbedBase {
// when we should record 2. The alternative is to add a lot of complexity
// to the update logic of our plugin, to deal with all possible
// combinations in the update scenario.
// @TODO Re-evaluate if this is worth the effort and overhead.
// @todo Re-evaluate if this is worth the effort and overhead.
$entities[$node->getAttribute('data-entity-uuid')] = $node->getAttribute('data-entity-type');
}
return $entities;
......
......@@ -9,12 +9,12 @@ use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Path\PathValidatorInterface;
use Drupal\Core\StreamWrapper\StreamWrapperInterface;
use Drupal\entity_usage\EntityUsageInterface;
use Drupal\entity_usage\EntityUsageTrackBase;
use Drupal\layout_builder\Plugin\Field\FieldType\LayoutSectionItem;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Path\PathValidatorInterface;
use Drupal\Core\StreamWrapper\StreamWrapperInterface;
/**
* Tracks usage of entities related in Layout Builder layouts.
......@@ -194,7 +194,7 @@ class LayoutBuilder extends EntityUsageTrackBase {
$ids = array_filter($ebbContentIds, function ($item) {
// Entity Browser Block stores each entity in "entity_ids" in the format:
// "{$entity_type_id}:{$entity_id}".
list($entity_type_id, $entity_id) = explode(":", $item);
[$entity_type_id, $entity_id] = explode(":", $item);
$storage = $this->entityTypeManager->getStorage($entity_type_id);
if (!$storage) {
return FALSE;
......@@ -236,7 +236,7 @@ class LayoutBuilder extends EntityUsageTrackBase {
$ids = array_map(function ($item) {
// Content dependencies are stored in the format:
// "{$entity_type_id}:{$bundle_id}:{$entity_uuid}".
list($entity_type_id, , $entity_uuid) = explode(':', $item);
[$entity_type_id, , $entity_uuid] = explode(':', $item);
if ($entity = $this->entityRepository->loadEntityByUuid($entity_type_id, $entity_uuid)) {
return "{$entity_type_id}|{$entity->id()}";
}
......
......@@ -37,7 +37,7 @@ class LinkIt extends TextFieldEmbedBase {
// when we should record 2. The alternative is to add a lot of complexity
// to the update logic of our plugin, to deal with all possible
// combinations in the update scenario.
// @TODO Re-evaluate if this is worth the effort and overhead.
// @todo Re-evaluate if this is worth the effort and overhead.
$entities[$node->getAttribute('data-entity-uuid')] = $node->getAttribute('data-entity-type');
}
return $entities;
......
......@@ -34,7 +34,7 @@ class MediaEmbed extends TextFieldEmbedBase {
// when we should record 2. The alternative is to add a lot of complexity
// to the update logic of our plugin, to deal with all possible
// combinations in the update scenario.
// @TODO Re-evaluate if this is worth the effort and overhead.
// @todo Re-evaluate if this is worth the effort and overhead.
$entities[$node->getAttribute('data-entity-uuid')] = $node->getAttribute('data-entity-type');
}
return $entities;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment