[07:05:09] | <skipper_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? |
[08:50:34] | <skipper_is[m]> | Could we rewrite the EntityAutocomplete function to use square brackets? |
[08:51:38] | <mstenta[m]> | I was thinking the same thing skipper_is :-) |
[08:51:56] | <mstenta[m]> | It would require a drupal core patch |
[08:51:56] | <skipper_is[m]> | I mean, we can physically do it, as I already have... but should we? |
[08:58:06] | <mstenta[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? |
[08:58:06] | <mstenta[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) |
[08:58:22] | <skipper_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` |
[08:58:25] | <mstenta[m]> | So what you get back in form submit will vary |
[08:58:56] | <skipper_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)` |
[09:00:31] | <mstenta[m]> | Instead of $this->entityTypeManager use \Drupal::service('entity_type_manager') |
[09:00:57] | <mstenta[m]> | (I might have the service name wrong, but that's how you use a service directly without using dependency injection |
[09:01:23] | <mstenta[m]> | Dependency injection is what allows you to say $this->... |
[09:01:53] | <mstenta[m]> | "Services" are basically just a special way of using classes |
[09:02:19] | <skipper_is[m]> | But why is it not using that class as is? |
[09:02:58] | <mstenta[m]> | You can some special goodies when you wrap it in a "service" like that |
[09:03:10] | <mstenta[m]> | For one, a module could replace the class being used |
[09:03:53] | <mstenta[m]> | We do that in the group module to override asset location service to take into account group location |
[09:04:06] | <mstenta[m]> | For example |
[09:04:33] | <mstenta[m]> | Drupal core provides a bunch of services, "entity type manager" is one of them |
[09:05:23] | <mstenta[m]> | > I mean, we can physically do it, as I already have... but should we? |
[09:05:23] | <mstenta[m]> | "as i already have"? What do you mean? |
[09:06:11] | <skipper_is[m]> | So, I've called $this->entityTypeManager, the same as Planting, should that not use that service? |
[09:06:36] | <mstenta[m]> | Oh well the planting quick form class injects that dependency. Yours doesn't |
[09:06:51] | <skipper_is[m]> | In the use section? |
[09:06:51] | <mstenta[m]> | That's what the constructor and create methods do basically |
[09:07:08] | <mstenta[m]> | And use, yes |
[09:07:25] | <mstenta[m]> | Take a look at the constructor and create methods of the planting class |
[09:07:26] | <skipper_is[m]> | /**... (full message at https://libera.ems.host/_matrix/media/r0/download/libera.chat/03119fa0c6...) |
[09:07:27] | <skipper_is[m]> | That? |
[09:07:32] | <mstenta[m]> | Yes that's part of it |
[09:07:58] | <skipper_is[m]> | Oh, I see it now |
[09:07:59] | <mstenta[m]> | That creates the property where the service will be stored in the class, so you can use $this->... |
[09:08:19] | <mstenta[m]> | You don't NEED to use dependency injection, but there are some benefits with performance |
[09:08:43] | <mstenta[m]> | And farmOS core coding standards will throw an error if you try to open a PR without it |
[09:09:11] | <mstenta[m]> | But it's not strictly required in order to work, so it's to to you in your module |
[09:09:24] | <mstenta[m]> | U*p to you |
[09:09:29] | <skipper_is[m]> | Probably best practice though |
[09:11:26] | <mstenta[m]> | Yea |
[09:11:46] | <mstenta[m]> | https://www.drupal.org/docs/drupal-apis/services-and-dependency-injectio... |
[09:14:31] | <mstenta[m]> | D8+ uses Symfony framework for all this |
[09:14:58] | <mstenta[m]> | One of the big benefits is it will intelligently autoload classes only when they are necessary |
[09:16:02] | <skipper_is[m]> | Another quick one - default unit taxonomy? Is there default units for metric/imperial? |
[09:16:12] | <mstenta[m]> | This doc is probably most relevant to quick forms: |
[09:16:13] | <mstenta[m]> | https://www.drupal.org/docs/drupal-apis/services-and-dependency-injectio... |
[09:17:06] | <mstenta[m]> | > Another quick one - default unit taxonomy? Is there default units for metric/imperial? |
[09:17:06] | <mstenta[m]> | No it's up to modules to define/provide that. farmOS core doesn't |
[09:18:26] | <skipper_is[m]> | ok |
[09:46:15] | <skipper_is[m]> | If I uninstall/reinstall a module, will it clear the StateInterface? |
[09:51:26] | <mstenta[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()` |
[09:52:05] | <skipper_is[m]> | And for making an info message thing, just drupal_set_message()? |
[09:52:17] | <mstenta[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 |
[09:52:56] | <mstenta[m]> | https://www.drupal.org/node/1667896 |
[09:52:57] | <mstenta[m]> | https://www.drupal.org/docs/upgrading-and-converting-drupal-7-modules/st... |
[09:53:50] | <mstenta[m]> | > And for making an info message thing, just drupal_set_message()? |
[09:53:50] | <mstenta[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 |
[09:54:38] | <skipper_is[m]> | found it messenger |
[09:54:51] | <mstenta[m]> | yea and i think that's injected into the quick form class by default |
[09:55:00] | <mstenta[m]> | so you can use it like $this->messenger, same as the trait does |
[10:02:47] | <skipper_is[m]> | ...How do you get the id of an entity? $entity->id()? |
[11:25:50] | <mstenta[m]> | Yup |
[11:34:17] | * farmBOT has joined #farmos |
[13:30:02] | <skipper_is[m]> | I don't quite understand why the PR is currently failing |
[13:32:36] | <mstenta[m]> | ACTION sent a code block: https://libera.ems.host/_matrix/media/r0/download/libera.chat/0146d543a1... |
[13:33:40] | <mstenta[m]> | hmm trying to understand what that means... |
[13:34:24] | <mstenta[m]> | oh looks like your docblock comment has different parameters than the actual `__construct` method |
[13:34:43] | <mstenta[m]> | or they are just in a different order |
[13:35:04] | <skipper_is[m]> | Ah, order probably... |
[14:18:54] | <skipper_is[m]> | Wehey! Passed |