- Status changed to Needs work
almost 2 years ago 11:08pm 20 January 2023 - Status changed to Needs review
almost 2 years ago 11:48pm 20 January 2023 - Status changed to Needs work
almost 2 years ago 3:20pm 21 January 2023 - 🇺🇸United States xjm
+++ b/core/modules/block/src/BlockForm.php @@ -88,14 +95,21 @@ class BlockForm extends EntityForm { + * @param BlockMachineNameGeneratorInterface $machine_name_generator + * The unique machine name generator. */ - public function __construct(EntityTypeManagerInterface $entity_type_manager, ExecutableManagerInterface $manager, ContextRepositoryInterface $context_repository, LanguageManagerInterface $language, ThemeHandlerInterface $theme_handler, PluginFormFactoryInterface $plugin_form_manager) { + public function __construct(EntityTypeManagerInterface $entity_type_manager, ExecutableManagerInterface $manager, ContextRepositoryInterface $context_repository, LanguageManagerInterface $language, ThemeHandlerInterface $theme_handler, PluginFormFactoryInterface $plugin_form_manager, BlockMachineNameGeneratorInterface $machine_name_generator = NULL) {
Oh, and since this defaults to null, it needs to be typed as
BlockMachineNameGeneratorInterface|null
in the docs and typehinted with nullable
?BlockMachineNameGeneratorInterface
in the signature. - Status changed to Needs review
almost 2 years ago 5:00pm 27 January 2023 - 🇨🇴Colombia fabiansierra5191
Thanks @xjm for the feedback,
I did all changes suggested except for the bullet 11 on the comment #71test_theme
variable is been using to replace the new theme in various places and I think we can keep it. - Status changed to RTBC
almost 2 years ago 6:19pm 27 January 2023 - 🇺🇸United States smustgrave
From what I can see points in #71 and #72 have been addressed
Good job!
- Status changed to Needs work
almost 2 years ago 10:28am 30 January 2023 - 🇬🇧United Kingdom alexpott 🇪🇺🌍
-
+++ b/core/modules/block/src/BlockMachineNameGenerator.php @@ -0,0 +1,53 @@ +/** + * {@inheritdoc} + */ +class BlockMachineNameGenerator implements BlockMachineNameGeneratorInterface {
Having a swappable block machine name generator service feels interesting. I'm not sure about this being part of the API. Also having {@inheritdoc} as a class doc feels wrong. Note sure I've seen that before.
Plus I wonder how this fits in with
✨ Strip useless "_" at beginning and end of JS-transliterated machine names Fixed which is pointing towards a need to consolidate the various places we generate machine names in core. -
+++ b/core/modules/block/src/BlockMachineNameGenerator.php @@ -0,0 +1,53 @@ + // Get all the block machine names that begin with the suggested string. + $query = $this->blockStorage->getQuery(); + $query->condition('id', $suggestion, 'CONTAINS'); + $block_ids = $query->execute();
Do we need to add an accessCheck() method here?
-
- Status changed to Needs review
almost 2 years ago 3:06pm 3 February 2023 - 🇨🇴Colombia fabiansierra5191
Thanks @alexpott for the feedback!
I addressed your points by changing the comment for
BlockMachineNameGenerator
class and setting theaccessCheck()
method.Hope this one is the one!
- Status changed to RTBC
almost 2 years ago 6:09pm 3 February 2023 - 🇺🇸United States smustgrave
Appears #75 was addressed
@alexpott looking at ✨ Strip useless "_" at beginning and end of JS-transliterated machine names Fixed seems to be removing a trailing _
Maybe they could adopt the solution we did here but that ticket may stalled as it hasn't been touched in 3 weeks. - Status changed to Needs review
almost 2 years ago 1:53pm 17 February 2023 - 🇨🇴Colombia fabiansierra5191
As the latest test results mention the
accessCheck()
function is not required here https://www.drupal.org/node/3201242 → , so about the last changes I remove this but kept the comment forBlockMachineNameGenerator
class - Status changed to RTBC
almost 2 years ago 2:23pm 17 February 2023 - 🇨🇴Colombia fabiansierra5191
Wrong file, so ticket moved to previous status
- Status changed to Needs work
almost 2 years ago 3:08pm 17 February 2023 - 🇺🇸United States bnjmnm Ann Arbor, MI
While I'm not 100% which patch is RTBC, all of the patches provided after @alexpott feedback are tripping "Custom commands failed" so that should be addressed before this can again be RTBC'd.
- 🇺🇸United States smustgrave
I think one of the weekly retests caused a phpstan error. Definitely wouldn't of marked RTBC if it was showing that before. So it's new.
- 🇺🇸United States xjm
#76 is the correct patch; #78 reverts one of the changes from it.
The failure on #76 is strange:
Running PHPStan on *all* files. ------ ----------------------------------------------------------------------- Line core/modules/block/src/BlockForm.php ------ ----------------------------------------------------------------------- Ignored error pattern #^Relying on entity queries to check access by default is deprecated in drupal\:9\.2\.0 and an error will be thrown from drupal\:10\.0\.0\. Call \\Drupal\\Core\\Entity\\Query\\QueryInterface\:\:accessCheck\(\) with TRUE or FALSE to specify whether access should be checked\.$# in path /var/www/html/core/modules/block/src/BlockForm.php was not matched in reported errors. ------ ----------------------------------------------------------------------- ------ ----------------------------------------------------------------------- Line core/modules/block/src/BlockMachineNameGenerator.php ------ ----------------------------------------------------------------------- 36 Relying on entity queries to check access by default is deprecated in drupal:9.2.0 and an error will be thrown from drupal:10.0.0. Call \Drupal\Core\Entity\Query\QueryInterface::accessCheck() with TRUE or FALSE to specify whether access should be checked. 💡 See https://www.drupal.org/node/3201242 ------ ----------------------------------------------------------------------- [ERROR] Found 2 errors
I think what this actually means is that the baseline is expecting an error there, and this patch is fixing it. So, we should try removing this hunk from the baseline as well and see if that resolves the issue:
- message: "#^Relying on entity queries to check access b\ y default is deprecated in drupal\\:9\\.2\\.0 and an error will be thrown from drupal\\:10\\.0\\.0\\. Call \\\\Drupal\\\\Core\\\\Entity\\\\Query\\\\QueryInterface\\:\\:accessCheck\\(\\) with TRUE or FALSE to specify whether access should be checked\\.$#" count: 1 path: modules/block/src/BlockForm.php
I have someone working on this now.
- Assigned to schlaukopf
- 🇦🇪United Arab Emirates schlaukopf Dubai
New changes were introduced on core/modules/block/src/BlockForm.php, so I did a rebase from #76 and fixed a conflict, and then I removed the line on core/phpstan-baseline.neon that was causing phpstan to fail.
diff --cc core/modules/block/src/BlockForm.php index 8eb188020e,4583ed58c0..0000000000 --- a/core/modules/block/src/BlockForm.php +++ b/core/modules/block/src/BlockForm.php @@@ -387,28 -402,7 +402,32 @@@ class BlockForm extends EntityForm */ public function getUniqueMachineName(BlockInterface $block) { $suggestion = $block->getPlugin()->getMachineNameSuggestion(); ++<<<<<<< HEAD + if ($block->getTheme()) { + $suggestion = $block->getTheme() . '_' . $suggestion; + } + + // Get all the blocks which starts with the suggested machine name. + $query = $this->storage->getQuery(); + $query->condition('id', $suggestion, 'CONTAINS'); + $block_ids = $query->execute(); + + $block_ids = array_map(function ($block_id) { + $parts = explode('.', $block_id); + return end($parts); + }, $block_ids); + + // Iterate through potential IDs until we get a new one. E.g. + // 'plugin', 'plugin_2', 'plugin_3', etc. + $count = 1; + $machine_default = $suggestion; + while (in_array($machine_default, $block_ids)) { + $machine_default = $suggestion . '_' . ++$count; + } + return $machine_default; ++======= + return $this->machineNameGenerator->getUniqueMachineName($suggestion); ++>>>>>>> df87c63266 (#76) }
- Status changed to Needs review
almost 2 years ago 5:11pm 26 February 2023 - Issue was unassigned.
- 🇺🇸United States xjm
Thanks @schlaukopf! Testing locally, this seems to resolve the PHPStan issue, and also addresses the merge conflict introduced by ✨ Prefix block machine name suggestions with the theme machine name Fixed .
So we now have the following in
core/modules/block/src/BlockForm.php
:public function getUniqueMachineName(BlockInterface $block) { $suggestion = $block->getPlugin()->getMachineNameSuggestion(); if ($block->getTheme()) { $suggestion = $block->getTheme() . '_' . $suggestion; } + return $this->machineNameGenerator->getUniqueMachineName($suggestion);
Question then is, does the logic of adding the theme prefix belong in
BlockForm
, or should we inject the theme into the machine name generator? - 🇺🇸United States xjm
Regarding #75.1 and whether we should consolidate machine name generation APIs, I think that's out of scope for this issue, since this is still fixing a major-possibly-critical data integrity bug. First of all, we'll need separate implementations in JS and PHP regardless -- the JS generates a suggested machine name for the user, but the PHP has to do its own validation either way.
Tagging for a followup issue to explore how we might consolidate the machine name generation APIs.
- Status changed to RTBC
almost 2 years ago 7:49pm 28 February 2023 - 🇺🇸United States smustgrave
Test #84
With claro + olivero installed
Created a block with machine name stark_page_title
Installed stark theme and get fatal error
Block is not created for stark theme
Applied patch
Repeated steps
Block got created for stark with machine name stark_stark_page_titleOpened 📌 Possibly consolidate machine name generation API Active per #87
- Status changed to Needs review
almost 2 years ago 8:13pm 2 March 2023 - 🇺🇸United States smustgrave
My mistake think I read #86 and #87 as the same
- 🇦🇪United Arab Emirates schlaukopf Dubai
if we want to move the theme prefixing to the new API, I think we need to move this from block_theme_initialize (core/modules/block/block.module) as well
if (str_starts_with($default_theme_block_id, $default_theme . '_')) { $id = str_replace($default_theme, $theme, $default_theme_block_id); } else { $id = $theme . '_' . $default_theme_block_id; } $id = \Drupal::service('block.machine_name_generator')->getUniqueMachineName($id);
perhaps the whole if/else statement?
- 🇦🇪United Arab Emirates schlaukopf Dubai
I moved the theme name as a function parameter, I didn't move the whole if-statement from #91, because I'm not sure if replacing the old theme prefix should apply to all calls to that function.
The last submitted patch, 93: 2858897_93.patch, failed testing. View results →
- Status changed to Needs work
over 1 year ago 8:01pm 13 March 2023 - 🇦🇪United Arab Emirates schlaukopf Dubai
This should fix the error in the pipeline
- 🇦🇪United Arab Emirates schlaukopf Dubai
This should fix the error in the pipeline
- Status changed to Needs review
over 1 year ago 1:21pm 14 March 2023 - Status changed to RTBC
over 1 year ago 6:33pm 14 March 2023 - Status changed to Needs work
over 1 year ago 8:39am 17 March 2023 - 🇦🇪United Arab Emirates schlaukopf Dubai
I forgot to rebase, so this is after #84 where I move the theme prefixing into the new API.
- Status changed to Needs review
over 1 year ago 9:42am 22 March 2023 - Status changed to RTBC
over 1 year ago 1:34pm 22 March 2023 - 🇺🇸United States smustgrave
Face palming myself for missing that. Thanks @laurii!
Followed the same steps in #88
The last submitted patch, 101: 2858897_101.patch, failed testing. View results →
- 🇫🇷France andypost
random failure
User.Drupal\Tests\user\Kernel\Migrate\MigrateUserStubTest
- Status changed to Needs review
over 1 year ago 1:14am 29 March 2023 - Status changed to RTBC
over 1 year ago 2:24pm 5 April 2023 - 🇺🇸United States tim.plunkett Philadelphia
It's probably overkill, but it fits with a standard Drupal level of overkill :D
Reviewed the code overall, and again with the lens of #106, and I think this is good to go
- 🇬🇧United Kingdom longwave UK
This could be a new method on the BlockRepository, instead of a separate service?
- Status changed to Needs work
over 1 year ago 3:26pm 6 April 2023 - First commit to issue fork.
- @rpayanm opened merge request.
- Status changed to Needs review
over 1 year ago 6:31pm 6 April 2023 - Status changed to RTBC
over 1 year ago 6:57pm 6 April 2023 - Status changed to Needs work
over 1 year ago 8:29pm 10 April 2023 - 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10
- last update
over 1 year ago Patch Failed to Apply 35:09 28:24 Running- First commit to issue fork.
- last update
about 1 year ago Custom Commands Failed - @ericgsmith opened merge request.
- last update
about 1 year ago 30,370 pass, 2 fail - last update
about 1 year ago 30,372 pass - Status changed to Needs review
about 1 year ago 1:19am 3 October 2023 - 🇳🇿New Zealand ericgsmith
- Rebased onto 11.x
- Moved method onto Block Repository service and removed block name generator service
- Updated deprecation warning
- Fixed test after rebaseThink that covers concerns from #75, #108 and #115 - setting as needs review.
- Status changed to Needs work
about 1 year ago 2:04pm 3 October 2023 - last update
about 1 year ago 30,392 pass, 2 fail - Status changed to Needs review
about 1 year ago 7:09pm 11 October 2023 - 🇳🇿New Zealand ericgsmith
I've updated the CR - its also ready for review.
I missed that it looks like the pipeline above failed, but its showing as tests pass on the issue itself. Rebasing and running again.
- last update
about 1 year ago Custom Commands Failed - last update
about 1 year ago 30,394 pass - Status changed to RTBC
about 1 year ago 8:59pm 11 October 2023 - Status changed to Fixed
about 1 year ago 7:29am 12 October 2023 - 🇬🇧United Kingdom alexpott 🇪🇺🌍
Committed and pushed 8339e0ebe6c to 11.x and 61030f7a4af to 10.2.x. Thanks!
-
alexpott →
committed 8339e0eb on 11.x
Issue #2858897 by ericgsmith, smustgrave, schlaukopf, fabiansierra5191,...
-
alexpott →
committed 8339e0eb on 11.x
-
alexpott →
committed 61030f7a on 10.2.x
Issue #2858897 by ericgsmith, smustgrave, schlaukopf, fabiansierra5191,...
-
alexpott →
committed 61030f7a on 10.2.x
- 🇺🇸United States mpotter
Here is a roll of this patch for D10.1.x that removes the `core/phpstan-baseline.neon` change that has already been applied to core.
- last update
about 1 year ago 29,675 pass Automatically closed - issue fixed for 2 weeks with no activity.