Need the ability to work with ECK entities

Created on 17 October 2023, 9 months ago
Updated 31 March 2024, 3 months ago

I wanted the module to be able to work with the creation of ECK entities.

Feature request
Status

Fixed

Version

2.0

Component

Code

Created by

🇷🇺Russia k.prozorov

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @k.prozorov
  • Status changed to Closed: works as designed 9 months ago
  • 🇮🇱Israel yakoub

    this module supports all entities .
    simply enable content translation for your eck entities under path : admin/config/regional/content-language
    and make sure to check "translations pack" like in the screenshot .
    https://www.drupal.org/files/project-images/Screenshot%20from%202023-05-...

  • Status changed to Active 9 months ago
  • 🇷🇺Russia k.prozorov

    Thanks for the answer!
    The module works perfectly with nodes.
    I want to use this module in combination with the module Entity Construction Kit (ECK)
    Yes I have enabled the "Translations pack" checkbox on the admin/config/regional/content-language path for my ECK entity.
    For the ECK entity editing form (for example by url /{eck_entity_type}/{entity_id}/edit) I can add /pack to the url (the url is /{eck_entity_type}/{entity_id}/edit/pack), then I will see tabs for switching languages.
    But this functionality is not available for the ECK entity creation form (for example, at the url /admin/content/{eck_entity_type}/add/{eck_entity_bundle})
    In the file, there is a route only for nodes.

    Tell me how can I use the module to create ECK entities with the ability to switch language tabs?

  • Assigned to yakoub
  • 🇮🇱Israel yakoub

    you are correct .
    i am working on it .
    the add new content route is defined in

    src/Routing/TranslationsPackRouteSubscriber.php
    

    i need to add support for eck or maybe define a new plugin type .

  • 🇷🇺Russia k.prozorov

    Can you tell me when approximately this can be done?
    Best regards.

  • 🇮🇱Israel yakoub

    it will be done this weekend .
    it is just a routing derivative .

  • 🇷🇺Russia k.prozorov

    It's going to be awesome!

    I made a temporary solution.

    In the file, I added a route like this:

    entity.eck.translations_pack_add:
      path: '/admin/content/{eck_entity_type}/add/{eck_entity_bundle}/pack'
      defaults:
        _title: 'Packed add form'
        _controller: '\Drupal\translations_pack\Controller\TranslationsPackController::build_add_eck'
      requirements:
        _permission: 'create MY_ECK_ENTITY_TYPE entities'
      options:
        _admin_route: true
        parameters:
          eck_entity_type:
            type: entity:eck_entity_type
            with_config_overrides: TRUE
    

    I have specified routing permissions for my ECK entity type.

    And added a method by analogy as it is done for node in the file :

    public function build_add_eck($eck_entity_type, $eck_entity_bundle, Request $request, RouteMatchInterface $route_match) {
        /* @var \Drupal\eck\Entity\EckEntityType $eck_entity_type */
        $values = ['type' => $eck_entity_bundle];
        $entity = $this->entityTypeManager()->getStorage($eck_entity_type->id())->create($values);
        $language = $this->languageManager()
          ->getCurrentLanguage(LanguageInterface::TYPE_CONTENT);
        $entity->set('langcode', $language->getId());
        $route_match = new MockRouteMatch($entity);
        return $this->build_pack($eck_entity_type->id(), $request, $route_match);
      }
    

    In this variant, I have the ability to create ECK entities immediately with translation tabs (It's probably better to specify this as a parameter from route).

    I also noticed an error in the browser console (it pointed to ajax.js) and I fixed this error by adding - core/drupal.ajax to the section in the file.

  • 🇮🇱Israel yakoub

    looks good .
    i am also working on support for inline entity form .

  • 🇮🇱Israel yakoub

    i refactored code to use entity handler, this way i can now continue to write custom handler for eck entities .
    https://git.drupalcode.org/project/translations_pack/-/commit/a278a804df...

  • 🇮🇱Israel yakoub

    this is working version, but the code still ugly and need fixing
    https://git.drupalcode.org/project/translations_pack/-/commit/cb24240f81...

  • 🇮🇱Israel yakoub

    current branch 2.0.x has working version, but :
    given the eck route for adding content is shared among different entity types, then the method of defining tabs will not work when one entity has translations pack enabled while another entity is not even defined as translatable .
    the solution instead of tabs is to add link for entity operations to dedicated add content route which loads the translations pack .
    this should be simple solution, but given i have fulltime job then it will need to wait several days maybe until the weekend .

  • 🇮🇱Israel yakoub

    current 2.0.x branch is ready for testing .
    do you require backporting to 1.0.x ?

  • Status changed to Needs review 8 months ago
  • 🇷🇺Russia k.prozorov

    , since drupal 9 is still popular, we need a version for drupal 9 as well

  • 🇮🇱Israel yakoub

    released in beta3

  • Status changed to Fixed 3 months ago
  • Status changed to Fixed 3 months ago
Production build 0.69.0 2024