AccountForm::form() contains the following code.
$form['#cache']['tags'] = $config->getCacheTags();
$language_interface = \Drupal::languageManager()->getCurrentLanguage();
Instead of calling \Drupal::languageManager(), it should use its own $this->languageManager property, which is initialized from the class constructor.
public function __construct(EntityRepositoryInterface $entity_repository, LanguageManagerInterface $language_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL) {
parent::__construct($entity_repository, $entity_type_bundle_info, $time);
$this->languageManager = $language_manager;
}
There is code in the same method that uses $this->languageManager, so this seems a forgetfulness in one of the past commits.
$form['language'] = [
'#type' => $this->languageManager->isMultilingual() ? 'details' : 'container',
'#title' => $this->t('Language settings'),
'#open' => TRUE,
// Display language selector when either creating a user on the admin
// interface or editing a user account.
'#access' => !$self_register,
];
Comments
Comment #2
saurabh.rocksoulHere is the patch for the issue, please review.
Comment #3
avpadernoComment #4
alexpottIf we're fixing this form for \Drupal use then let's also fix
$config = \Drupal::config('user.settings');- that can be$config = $this->config('user.settings');Plus in other similar issues about \Drupal usage we've pushed back and asked this to be done on the module level - so can we need to do
Comment #5
hardik_patel_12 commentedCovered all points as mentioned by @alexpott , Kindly review.
Comment #7
swatichouhan012 commentedComment #8
swatichouhan012 commentedWe can not used $this in static method i have removed from above page, kindly review
Comment #9
swatichouhan012 commentedComment #11
hardik_patel_12 commentedSolving test case failures , kindly review a new patch.
Comment #12
hardik_patel_12 commentedComment #14
avpadernoThe tests are failing because of errors similar to the following one.
I am not sure if the error is caused by this patch or other changes in the code.
There are also coding standard issues in the patch. (See https://dispatcher.drupalci.org/job/drupal_patches/34651/artifact/jenkin....)
Comment #15
avpadernoThere is a missing space between the parentheses at the end of the first line.
There is a missing space between the parentheses at the end of the first line.
Comment #16
hardik_patel_12 commentedKindly review a new patch.
Comment #17
hardik_patel_12 commentedComment #18
avpadernoThe error I shown in comment #14 is caused by this patch: A class that extends the
PluginBaseclass cannot also implement theContainerInjectionInterfaceinterface.PluginBase::create()andContainerInjectionInterface::create()have different parameters.Comment #19
hardik_patel_12 commented@kiamlaluno thanks for reviewing the patch , yes i have noticed that and removed the implementation of ContainerInjectionInterface and tried to make compatible with PluginBase::create() in patch #16.
Comment #20
avpadernoThere is still a missing space between ) and {; there is also an extra space between $container and the following comma. Search for ){: The patch contains 3 of them.
Comment #21
hash6 commentedComment #22
hash6 commentedComment #23
avpadernoThe patch includes unrelated changes.
Comment #24
hash6 commentedComment #25
hash6 commentedComment #26
hash6 commentedComment #28
hardik_patel_12 commentedTries to solve failure test , kindly review a new patch.
Comment #29
swatichouhan012 commentedHii @Hardik_Patel_12, @kiamlaluno
i have solved codesniffer issue regarding comment #15, also tries to solve test cases.
Comment #31
swatichouhan012 commentedpatch #28 got pass, kindly avoid #29, i am moving for review of #28.
Comment #32
swatichouhan012 commentedComment #33
kishor_kolekar commentedThere are some more coding standards that need to fixed in #28
Comment #34
kishor_kolekar commentedkindly review a new patch.
Comment #35
neelam_wadhwani commentedComment #36
neelam_wadhwani commentedComment #37
init90Thanks for work here. Some minor problems from the last patch:
I think there should be:
"Only show name field on registration form or when user can change own username."
I think that "The config factory." will be better here.
$config_factory instead of $config will be more correctly here
"The config factory."
Required params should be passed before optional.
But in that case, we can have potential BC problems(unsure about it).
We should use {@inheritdoc} here.
Here also should be {@inheritdoc}
Here also should be used {@inheritdoc}
{@inheritdoc} should be used
{@inheritdoc} should be used
{@inheritdoc} should be used
The previous variant looks more correctly for me
Comment #38
kishor_kolekar commented@init90 patch adjusted according to #37 please review the patch.
Comment #39
kishor_kolekar commentedComment #41
neelam_wadhwani commentedHello @init90
Updated the changes as asked for.
Kindly review patch.
Comment #42
neelam_wadhwani commentedComment #43
jungle- * @param \Drupal\Core\Config\ConfigFactoryInterface config_factory
+ * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
Comment #44
neelam_wadhwani commentedComment #45
jungleAny thought on this? Unexpected change or change it to the below.
Change lazy_builder to Lazy_builder does not make sense even the first letter must be uppercase, or no
_- Lazy_builder
+ Lazy builder
Comment #46
init90In core mostly used: "#lazy_builder callback;", so I think the optimal way doesn't change comment in the patch.
Some points which need to fix:
Now the comment is longer than 80 charsets, so the part of it should be moved to the next line.
The config factory.
$config_factory instead of $config
The config factory.
As I wrote earlier we shouldn't pass the required parameter after optional, but I don't know the correct solution in that case. Ignore the point yet.
Here should be {@inheritdoc} instead of comment.
It can be a bit nicer:
Comment #47
kishor_kolekar commented@init90 Updated the changes please review the patch .
Comment #49
avpadernoThis is just a quick review.
Making a comment shorter than 80 characters doesn't mean to put a period where it should not be. Also, the sentence is better as Show the name field only on registration forms or when users can change their own username.
There is a missing space in field,which.
#lazy_builder is correct. The phrase should be the following.
(It's a correct sentence and it's not longer than 80 characters.)
I also think that when the parameters of a class constructor are changed, there is something more to do, to provide BC.
Comment #50
jungleWorking on this
Comment #51
jungleIngored #47, started from #43. Addressed concerns in #46 and #49
By changing the last one to optional.
Exceeds 80 chars, break it to 3 lines -- Title, an empty line, the rest.
I am thinking to do it without touch the class constructor(s) if BC matters.
See this post for more https://www.previousnext.com.au/blog/safely-extending-drupal-8-plugin-cl...
Comment #52
jungleComment #53
jungleRevert IS changes unintendedly
Comment #54
init90Thanks, @jungle, looks really good.
One minor concern before RTBC, in
UserLoginBlockwe addRedirectDestinationservice but actually not use it. Let's start do it:)Comment #55
abhisekmazumdarRe-rolling the patch.
Comment #56
abhisekmazumdarComment #57
avpadernoThe BC is still missing. Simply adding new arguments to a service class is not possible. That is why Drupal core gives a default argument equal to
NULLto the new arguments, and calls@trigger_error()if the argument isNULL.The short description should say more than The #lazy_builder callback. If The #lazy_builder callback: It renders a form action URL including the destination. is too long, it's enough to use #lazy_builder callback: Renders a form action URL including the destination. which is similar to the example (Page callback: Displays a list of content.) shown in API documentation and comment standards.
Comment #58
init90@abhisekmazumdar thanks, changes looks good. I missed that
renderPlaceholderFormActionis static method and we cannot use injectedRedirectDestinationfor it.@kiamlaluno according to that https://www.drupal.org/core/d8-bc-policy#constructors seems that we can change the constructor params for plugins, so if you agree with it, then we can solve your second notice about the comment and go further.
Comment #59
avpaderno@init90 It's better to see what other patches that changed the parameters of a plugin class constructor did.
Comment #60
init90@kiamlaluno you're right we really should provide BC layer. Here issue with a similar discussion #3018863: Make SystemMenuBlock's new constructor argument dependency optional
And issue which might make life much easier for such a situation: #3019332: Use final to define classes that are NOT extension points
As a resume, in order to move further need to solve points from #57
Comment #61
avpadernoI thought it was necessary for those cases where the service container is not re-built, but I don't find any comment saying this is the reason for adding the code I reported in comment #57.
I am looking forward to when classes will be marked as final. Providing patches for Drupal will be much easier.
Comment #62
mradcliffeI performed Novice Triage on this issue. I am leaving the Novice tag on this issue because I think that updating the issue summary with some of the latest discussions would be a good novice task.
Comment #63
xjmOnly bug fixes and allowed changes during the beta phase should be filed against 9.0.x. New features, API additions, and deprecations should be filed against 9.1.x.
The scope of this issue is also questionable. While the end goal of this issue is a good one (using properly injected services where possible), we should scope changes by concept, not by file group or module. So, it would be better to have an issue that looked at
\Drupal::foo()usage on a per-method basis, rather than a per-module basis. And if the scope of that turns out to be too large, then we would break it down an additional level with (e.g.) "Use$this->foo()instead of\Drupal::foo()in form classes."So, work on this should be postponed until we split up the issues more correctly. I suspect there is an existing meta issue for this, so I would search for that meta and use it to rescope this. Thanks!
Comment #64
jungleComment #65
xjmYep that's it, thanks @jungle!
Comment #66
xjmAlright, thanks everyone for your contributions so far!
I am closing this as a duplicate of #2729597: [meta] Replace \Drupal with injected services where appropriate in core. You can use the work in the patches from this and similar issues as starting points for new issues scoped by concept.