Een hart voor de Drupal Community

Bij make it fly geloven we sterk in Drupal en Open Source software in het algemeen. We maken dagelijks gebruik van vele open source componenten en de vele Drupal modules die beschikbaar zijn. We dragen actief ons steentje bij aan de community door zelf patches, modules en documentatie te voorzien, daarnaast zijn enkele teamleden ook actief in de Drupal User Group vzw.

Een overzicht van onze bijdragen aan de Drupal community vind je terug op onze Drupal.org pagina. Naast het actief meerwerken aan de Drupal community, zetten we ook andere ontwikkelaars op weg door vragen te beantwoorden op Drupal Answers.

  1. Don't hardcode 'value' key for textual field translation

    Sven Decabooter

    Problem/Motivation

    Currently, the logic in AI Translate module assumes all textual content to be translated is in the fields 'value' property. See \Drupal\ai_translate\Controller\AiTranslateController::translateSingleText().

    There are scenario's where text-to-be-translated will not be stored in the 'value' property though. Some examples:

    • Issue for link field translation: #3529669: Handle link field translation as well - although this works around the limitation by putting the link title into the 'value' property upon extraction. Only works if there is 1 property to be translated though.
    • #3529794: Add support for AI submodule "ai_translate" FieldTextExtractor plugin: Custom Field module, which allows any arbitrary name to be used for the subfield / property that gets defined.

    Proposed resolution

    Make the property name to extract part of the metadata, and set it dynamically, instead of hardcoded 'value' property? I haven't dug deeper into the full architecture, to know if this is possible...

  2. Add support for AI submodule "ai_translate" FieldTextExtractor plugin

    Sven Decabooter

    Problem/Motivation

    The AI module's submodule "ai_translate" provides content translation service through AI. It provides a plugin called FieldTextExtractor, which allows it to extract textual data from different kinds of field types, in order to pass those to an AI service for translation.

    Textual subfields provided by the custom_field module do not get translated through that mechanism, because there is no support for it in this module.

    Steps to reproduce

    - Install custom_field, ai & ai_translate modules - Set up a custom field with textual data - Try to translate an entity containing this field, via the AI translation mechanism

  3. When building a webform and saving elements the succes message is rendered behind the drupal sidebar

    Fons

    Problem/Motivation

    When building a webform and saving elements the succes message is rendered behind the Drupal sidebar.

    This is the topic for another discussion but I've always wondered why Webform has it's own way of showing messages instead of using the standard way that is provided in Drupal.

    Steps to reproduce

    Build a webform, add some form elements and click the save elements button.

  4. [5.0.0-alpha3] Menu items do not get is-active class

    Sven Decabooter

    I applied the MR logic from #3508748: [2.0.x] Add ability to track active menu items in menu source. Then in ui_suite_daisyui:menu component, I add a check:

    {% if item.in_active_trail %}
          <!-- Try adding extra class here -->
    {% endif %}
    

    That doesn't seem to work... Maybe I'm missing some additional context

  5. Support Drupal core DefaultContent API

    Sven Decabooter

    OK it should be possible after all I think.

    Say we can integrate with the contrib Default Content module, to produce output as follows:

    field_logos:
        -
          logo:
            entity_type: 'media'
            entity: eab657e0-3320-41d2-ab4e-53a09b397758
          link: 'https://google.com'
          link__title: ''
          link__options: { }
    

    (if not possible, worst case we need to document the exported YAML files have to be manually edited).

    Then in CustomFieldEntityReference::setValue(). we can do something like:

      /**
       * {@inheritdoc}
       */
      public function setValue($value, $notify = TRUE): void {
        $entity = $value['entity'] ?? NULL;
        // START ADDED LOGIC.
        if (is_array($value)) {
          if ($value['entity_type'] && Uuid::isValid($value['entity'])) {
            $entity = \Drupal::entityTypeManager()->getStorage($value['entity_type'])->loadByProperties(['uuid' => $value['entity']]);
            $entity = !empty($entity) ? current($entity) : NULL;
          }
        }
        // END ADDED LOGIC.
        if ($entity instanceof EntityInterface) {
          ...
       }
    

    I can spend some time to look further into this, but am currently time restrained, so just doing some braindump here. Will try to elaborate on it next week. Let me know if it would be a workable solution to extend the setValue() logic, for the use case of default content exports / imports.

  6. Support Drupal core DefaultContent API

    Sven Decabooter

    Did some more digging, and it seems the datatype used in custom_field module is "CustomFieldEntityReference", which does not inherit from core "EntityReference" data type, so guess this will never work :'(

  7. Support Drupal core DefaultContent API

    Sven Decabooter

    Problem/Motivation

    I have created a custom_field instance with the following properties: - logo: entity reference to Media entity - link: link field

    In a recipe, I'm using the Drupal core DefaultContent API to add default content upon application of the recipe. However, this does not work well with the custom_field I have.

    When I export the node containing this field (with the contrib Default Content module), I get something like:

    field_logos:
        -
          logo: 14
          link: 'https://google.com'
          link__title: ''
          link__options: { }
    

    Obviously directly linking to media ID 14 won't work, because the recipe will be installed on a site that might have different auto-increment IDs.

    I tried editing this to use the entity UUID, like other entity references exported via Default Content module:

    field_logos:
        -
          logo: eab657e0-3320-41d2-ab4e-53a09b397758
          link: 'https://google.com'
          link__title: ''
          link__options: { }
    

    This doesn't work either.

    Looking deeper into the core Importer class (\Drupal\Core\DefaultContent\Importer::setFieldValues()), I notice this only works for EntityReference data types: if ($property instanceof EntityReference) { ... } (full namespace = Drupal\Core\Entity\Plugin\DataType\EntityReference)

    I'm not familiar enough with the data model of custom_module, but I assume this uses something custom, instead of the core EntityReference data type, and thus does not set the value correctly. Would there be any way to make this work (without hacking core I presume)?

Sven Decabooter - Drupal Developer

"Onze teamleden bouwen zelf ook mee aan ons geliefde Drupal, en daar zijn we trots op"

Sven Decabooter
Drupal developer

Betrouwbare technologie, naadloze prestaties. Dat zijn onze Drupal-oplossingen.