Closed (fixed)
Project:
Flag
Version:
8.x-4.x-dev
Component:
Flag core
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
10 Aug 2015 at 11:05 UTC
Updated:
25 Aug 2015 at 00:14 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
martin107 commentedI should have done it like this the first time:)
Comment #3
joachim commentedThanks for filing this, and the patch
I'm thinking that we should maybe add some test coverage for this, as obviously there isn't any given our code was broken here! (Probably should have done that in the bugfix issue TBH...)
Doesn't need to be fancy -- just create a basic flag programmatically, flag a node (programmatically will do too here, we're not testing the flagging UI), then reset it with the form, then query to check there are no more flaggings.
This looks the same as the docs I found, but I've not yet seen an explanation of how it works. How does the property name $this->flagService get magically determined? (This is a nitpick at the docs, not the patch!)
Comment #4
martin107 commentedI can give a short chain of logic.
1) FlagResetForm is build in a factory.
2) FlagResetForm::create() is called by the factory to determine the parameters used in preparing the call to " new FlagResetForm(....)"
3) FlagResetForm::__construct is called after which $this->flagService is populated.
FormBase implements and overrides a method "create()" as part of it contract to implement \Drupal\Core\DependencyInjection\ContainerInjectionInterface
and the documentation in there says all this in more formal language..
My argument would be better if I could put my finger on the exact factory... what I do know is that this is not a symfony convention ... so it has to exist as somewhere in the logic glueing Drupal8 onto on of it.
I hope this helps.
I will get to the integration testing sometime this week....
Comment #5
joachim commentedBut more specifically, how does it know to call it flagService and not ElectricBoogaloo? Or flag_service (which IIRC is the name of it in the services.yml file)?
And thanks -- if you can work on the tests that would be ace. I'm getting very little free time to code at the moment.
Comment #6
martin107 commentedAh your understanding is correct, but the name for the service in the flag.services.yml file is 'flag'
and that is what I had to plumb into FlagResetForm::create().
PS
Just to fill in something I did not know when I wrote #4 When I say factory ... well in this case
it looks like the routing of all forms go through \Drupal\Core\Controller\FormController.
The first line of FormController::getContentResult extracts the class from the _form parameter in the routing file.
public function getContentResult(Request $request, RouteMatchInterface $route_match) {
$form_arg = $this->getFormArgument($route_match);
Comment #7
joachim commented> Ah your understanding is correct, but the name for the service in the flag.services.yml file is 'flag'
Ah, right, so the property name is fooService, where foo is the name in your services.yml file.
Comment #8
berdirNo. There is no connection between those two things. Or the only thing that does connect them is the create() and __construct() method, you can name those properties however you want.
The only magic that is involved here is that the form system knows to call the create() method if it exists. Then everything is controlled by those two methods.
Comment #9
martin107 commentedI hope I am not labouring the point, but it is the order of the parameters, not the name,
that ties the services collected in the create function to the parameters passed into the constructor.
the book module has a more complex example.
Comment #10
joachim commentedAh right, I've got it now. Sorry, was being totally dense earlier! create() gets the container passed to it, and 'new static()' causes __construct() to be called. Thank you both for your patience!
Comment #11
joachim commentedTests should wait for #2501811: Create FlagTestBase to house common functions, so I'm going to commit this now and file a follow-up.
Comment #13
martin107 commentedFollow up has been created..