Account created on 1 November 2006, about 18 years ago
#

Recent comments

🇨🇭Switzerland titouille

Hi,

Not sure if the case is the same, but...

I have a custom entity module that build a "single page" system. This one is based on two entities : single_page and single_page_item.

The single_page entity is a basic entity to build single pages. The single_page_item entity is a system of items that are attached to the single page to create multiple contents.

single_page_item has a canonical path to show a list of items in a tab of the single_page entity instance. On this list, I have a "create new item" button as action link (in single_page.links.action.yml). The route to create a new single page item (in single_page.routing.yml) has as requirement :

_entity_create_access: 'single_page_item'

But when I display the single_page item list within a group, the button doesn't exists.

I implemented the getPermission and buildPermissions like this :

  /**
   * {@inheritdoc}
   */
  public function getPermission($operation, $target, $scope = 'any') {

    switch ($operation) {
      case "create single_page_item":
        return $this->getEntityCreateSinglePageItemPermission();
    }

    return $this->parent->getPermission($operation, $target, $scope);
  }
  /**
   * {@inheritdoc}
   */
  public function buildPermissions() {
    $permissions = $this->parent->buildPermissions();

    // Instead of checking whether this specific permission provider allows for
    // a permission to exist, we check the entire decorator chain. This avoids a
    // lot of copy-pasted code to turn off or rename a permission in a decorator
    // further down the chain.
    $provider_chain = $this->groupRelationTypeManager()->getPermissionProvider($this->pluginId);

    $prefix = 'Single Page Item:';
    if ($name = $provider_chain->getPermission('create single_page_item', 'entity')) {
      $permissions[$name] = $this->buildPermission("$prefix Create new entity");
    }
    return $permissions;
  }

  /**
   * Gets the name of the create single page item permission for the entity.
   *
   * @return string|false
   *   The permission name or FALSE if it does not apply.
   */
  protected function getEntityCreateSinglePageItemPermission() {
    if ($this->definesEntityPermissions) {
      return "create $this->pluginId single_page_item";
    }
    return FALSE;
  }

The permission appears on the list of permissions in the group, the tested user has the "administrator" role and the permission is checked for it, but when I navigate to the items list, the button is not displayed. I set up a breakpoint to see if the permission is checked but there is only calls for entity.view, entity.update and entity.delete. It seems the action links are not triggering the permissions checks...

Maybe anyone can point me what I'm doing wrong ?

Thanks in advance.

🇨🇭Switzerland titouille

Hi !!

In the same way, it seems a "hook_themes_uninstalled" was added since 8.9.x in core. Is it possible to implement it on the hook_event_dispatcher module to allow acting on this particular hook ?

Thanks in advance.

🇨🇭Switzerland titouille

Thanks @VasyOK for the tip, working perfectly.

🇨🇭Switzerland titouille

Ok, so if anyone search a quick answer to this problem, I solved it like this.

Because I have a IDXFetcherResult extending FetcherResult, I can override the "cleanUp" method.

I have a IDXFileFetcher too, with fetch() method. I used this fetch method to pass to the IDXFetcherResult constructor the $feed and the "update_non_existent" state :

return new IDXFetcherResult(
  $path,
  $feed,
  $this->feedType->getProcessor()->getConfiguration('update_non_existent')
);

Now, on my IDXFetcherResult, I implemented the cleanUp method like this :

  public function cleanUp() {

    // Get file content as string.
    $content = file_get_contents($this->filePath);

    // Check if file is empty.
    // If it's the case, and only if it's the case, we must
    // clean ALL previously imported items.
    // We must add this process because the standard feeds system
    // doesn't clean items when it encount an empty list.
    if (empty(trim($content))) {

      $storage = \Drupal::entityTypeManager()
        ->getStorage('my-entity-type');

      // Get list of entities to clean.
      $ids = $storage
        ->getQuery()
        ->accessCheck(FALSE)
        ->condition('feeds_item.target_id', $this->feed->id())
        ->condition('feeds_item.hash', $this->updateNonExistent, '<>')
        ->execute();

      if (!empty($ids)) {
        /** @var \Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher $dispatcher */
        $dispatcher = \Drupal::service('event_dispatcher');

        $entities = $storage->loadMultiple($ids);

        // Iterate over each entity and mimic the clean process.
        // We use the same process to avoid potential errors.
        foreach ($entities as $entity) {

          $dispatcher->dispatch(new InitEvent($this->feed, 'clean'), FeedsEvents::INIT_IMPORT);
          $dispatcher->dispatch(new CleanEvent($this->feed, $entity), FeedsEvents::CLEAN);
        }
      }
    }
  }

Hope this can help.

🇨🇭Switzerland titouille

Hi Jaypan !

This is unfortunately not the case. If you don't declare "uuid" => "uuid" in primary keys of your custom entity, the uuid column will be not added to the database "base_table" of your entity.
And if you declare it after deployment, Drupal add this column into the "data_table" instead of "base_table" if your entity declare data_table, and this break the use of uuid...

I finally found exactly what I need with this post that explain how to add uuid property / column to a deployed entity : https://drupal.stackexchange.com/questions/302719/how-can-i-add-a-proper...

Best regards.

🇨🇭Switzerland titouille

same problem as megadesk3000 on #5. After upgrading to 1.3.0-beta1, I can't add new modules if symfony_mailer is enabled, it cause a Circular reference detected error :

PHP Fatal error: Uncaught Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException: Circular reference detected for service "entity_type.manager", path: "user_last_access_subscriber -> entity_type.manager -> string_translation -> string_translator.locale.lookup -> config.factory -> plugin.manager.email_builder".

downgrading to 1.2.1 resolve the problem.

Production build 0.71.5 2024