< 252022-02-26⋎27 >

Topic for #farmOS is: farmOS (farmos.org) is a free and open source, web-based farm management system. User guide: farmos.org/guide/ - Forum: farmOS.discourse.groupSet by mstenta on 2021-06-15 at 12:52
12:05skipper_is[m]With the autocomplete, is there an underlaying array that is created containing the assets etc? There is a reference to 'target_id' in the seasons one?
13:50skipper_is[m]Could we rewrite the EntityAutocomplete function to use square brackets?
13:51mstenta[m]I was thinking the same thing skipper_is :-)
13:51mstenta[m]It would require a drupal core patch
13:51skipper_is[m]I mean, we can physically do it, as I already have... but should we?
13:58mstenta[m]> With the autocomplete, is there an underlaying array that is created containing the assets etc? There is a reference to 'target_id' in the seasons one?
13:58mstenta[m]Yes, and I found that sometimes you get a target id and sometimes you get a full entity object. Depending on whether or not you are allowing "auto create" (eg with taxonomy terms)
13:58skipper_is[m]And getting assets from the autocomplete form... how? I'm using the example from Planting's taxonomy terms, `$crop = $this->entityTypeManager->getStorage('taxonomy_term')->load($crop);` but swapping out `taxonomy_term` for `asset`
13:58mstenta[m]So what you get back in form submit will vary
13:58skipper_is[m]`rror: Call to a member function getStorage() on null in Drupal\farm_quick_weight\Plugin\QuickForm\Weight->submitForm() (line 148 of /var/www/farmOS2/web/sites/all/modules/farm_quick_weight/src/Plugin/QuickForm/Weight.php)`
14:00mstenta[m]Instead of $this->entityTypeManager use \Drupal::service('entity_type_manager')
14:00mstenta[m](I might have the service name wrong, but that's how you use a service directly without using dependency injection
14:01mstenta[m]Dependency injection is what allows you to say $this->...
14:01mstenta[m]"Services" are basically just a special way of using classes
14:02skipper_is[m]But why is it not using that class as is?
14:02mstenta[m]You can some special goodies when you wrap it in a "service" like that
14:03mstenta[m]For one, a module could replace the class being used
14:03mstenta[m]We do that in the group module to override asset location service to take into account group location
14:04mstenta[m]For example
14:04mstenta[m]Drupal core provides a bunch of services, "entity type manager" is one of them
14:05mstenta[m]> I mean, we can physically do it, as I already have... but should we?
14:05mstenta[m]"as i already have"? What do you mean?
14:06skipper_is[m]So, I've called $this->entityTypeManager, the same as Planting, should that not use that service?
14:06mstenta[m]Oh well the planting quick form class injects that dependency. Yours doesn't
14:06skipper_is[m]In the use section?
14:06mstenta[m]That's what the constructor and create methods do basically
14:07mstenta[m]And use, yes
14:07mstenta[m]Take a look at the constructor and create methods of the planting class
14:07skipper_is[m]/**... (full message at libera.ems.host/_matrix/media/r0/downloa)
14:07skipper_is[m]That?
14:07mstenta[m]Yes that's part of it
14:07skipper_is[m]Oh, I see it now
14:07mstenta[m]That creates the property where the service will be stored in the class, so you can use $this->...
14:08mstenta[m]You don't NEED to use dependency injection, but there are some benefits with performance
14:08mstenta[m]And farmOS core coding standards will throw an error if you try to open a PR without it
14:09mstenta[m]But it's not strictly required in order to work, so it's to to you in your module
14:09mstenta[m]U*p to you
14:09skipper_is[m]Probably best practice though
14:11mstenta[m]Yea
14:11mstenta[m]www.drupal.org/docs/drupal-apis/services
14:14mstenta[m]D8+ uses Symfony framework for all this
14:14mstenta[m]One of the big benefits is it will intelligently autoload classes only when they are necessary
14:16skipper_is[m]Another quick one - default unit taxonomy? Is there default units for metric/imperial?
14:16mstenta[m]This doc is probably most relevant to quick forms:
14:16mstenta[m]www.drupal.org/docs/drupal-apis/services
14:17mstenta[m]> Another quick one - default unit taxonomy? Is there default units for metric/imperial?
14:17mstenta[m]No it's up to modules to define/provide that. farmOS core doesn't
14:18skipper_is[m]ok
14:46skipper_is[m]If I uninstall/reinstall a module, will it clear the StateInterface?
14:51mstenta[m]I don't think so - I don't think it tracks which modules adds state variables, so you should clean up after yourself in `hook_uninstall()`
14:52skipper_is[m]And for making an info message thing, just drupal_set_message()?
14:52mstenta[m]FYI in D7 there was `variable_set()` and `variable_get()` - in D8+ this has been removed and now you have "config" and "state" as separate concepts
14:52mstenta[m]www.drupal.org/node/1667896
14:52mstenta[m]www.drupal.org/docs/upgrading-and-conver
14:53mstenta[m]> And for making an info message thing, just drupal_set_message()?
14:53mstenta[m]no - it's a service now... i forget off the top of my head, but if you look at the `QuickLogTrait::createLog()` you'll see it uses it
14:54skipper_is[m]found it messenger
14:54mstenta[m]yea and i think that's injected into the quick form class by default
14:55mstenta[m]so you can use it like $this->messenger, same as the trait does
15:02skipper_is[m]...How do you get the id of an entity? $entity->id()?
16:25mstenta[m]Yup
16:34*farmBOT has joined
18:30skipper_is[m]I don't quite understand why the PR is currently failing
18:32*sent a code block: libera.ems.host/_matrix/media/r0/downloa
18:33mstenta[m]hmm trying to understand what that means...
18:34mstenta[m]oh looks like your docblock comment has different parameters than the actual `__construct` method
18:34mstenta[m]or they are just in a different order
18:35skipper_is[m]Ah, order probably...
19:18skipper_is[m]Wehey! Passed

< 252022-02-26⋏27 >