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