entities – Publishing Content is very slow

I noticed something on my site, whenever I press on publish in order to publish a content, the process takes around 2 to 3 minutes ! and if I edit a node and save the changes , the process is also really slow. There are no errors in the log messages . And when I wait for the 3 minutes, the content is published successfully. So the main issue is just being slow ..Any idea why?

database design – Cardinality in a Logical Model by number of rows Vs natural relationship between entities

How should one determine Cardinality in a Logical Model ?

Should it be based on how the rows of an entity relate to another entity or should we consider the natural relationship between the entities i.e. conceptual relationship between the entities ?

Example: If I have an entity Course and an entity Course Type, what would be the cardinality ? Each course can have only one course type. For example, Bachelor of Arts is a course of course type Bachelors and Master of Science is of course type Masters

If I have Course Type as part of Course entity, then Course Type would only contain list of valid course types and it would be “many-to-one” (non-identifying) as there are many courses which will could 1 course type.

On the other hand if I model it in such a way that Course Type entity has Course ID (foreign Key) and Course Type , then the relationships between Course and Course Type is “one-to-one” (identifying).

Basically what I am trying to understand is, which one the following is right ?

each course has one course type OR many courses have one course type

How should one make this decision ? Are there any guidelines ?

P.S. : I am a beginner and using Oracle Data Modeler

entities – How to properly manage field types for a content type created by a module for Drupal 9?

I’m a bit confused about two different errors I get, which seem to contradict each other. I guess I didn’t register my field types properly. The first one appears when I try to uninstall my module.

DrupalCoreFieldFieldException: Attempt to create a field field_example that does not exist on entity type node. in DrupalfieldEntityFieldConfig->getFieldStorageDefinition() (line 312 of coremodulesfieldsrcEntityFieldConfig.php).

The second one appears as an error message within the UI when I try to fix it by introducing another module which should only create the field type.

Unable to install Helper, field.field.node.content_type_example.field_example already exists in active configuration.

In general, the module calls an external API and fetches data which is then used to create nodes with several fields. These are defined inside the config/install directory. Furthermore, inside src/Plugin/Field there are FieldType, FieldFormatter and FieldWidget classes, more or less as described here.

I used this module when I tried to fix the first error without a helper module. With its help, I removed the field types created by my module in the first place. Unfortunately, I don’t know a lot about drush, which seems to be capable of solving the issue. On the other hand, it would be great if it was possible to “reset” the content type and the field types programmatically whenever the module is installed or uninstalled. So far, I tried the following code, without much luck:

// mymodule.install file
use DrupalfieldEntityFieldStorageConfig;

function mymodule_install() {
  if (FieldStorageConfig::loadByName('node', 'field_example')) {
    FieldStorageConfig::loadByName('node', 'field_example')->delete();

Does someone know how I can fix the error and how I should manage these fields in the future? Thanks!

entities – Guidance on entity reference – tokens or token parsing tools suggestions?

I have 3 content types – Organization, Site and Station. Stations related to a Site. Sites related to an Organization. A user can update is ‘location’ to show where they are working that day.

I use a token to show the user’s current ‘location’. I can’t seem to parse the location to reflect the Organization relationship.

EG; user is at gate 1. Gate 1 is part of site ‘Campus’. Campus is part of site ‘UC Berkeley’.

I get perfect results for Site : [current-user:field_current_location:entity:field_reference_location]
and I get perfect results for Station: [current-user:field_current_location]
but I can’t get the correct token to show the current related Organization.
My latest attempt was : [current-user:field_current_location:entity:field_reference_organization:entity]

Suggestions? is there a token parse module that shows values realtime I can rely on?

entities – How translate Config Entity?

Hello everyone how are you?

I created a ConfigEntity with some fields:

  • Title (textfield)
  • Body (CKEditor)

After that I insert the first item:

  • Title = “Hello World”
  • Body = “This is a test”

And now I need to translate this Entity to show “Title” and “Body” in the Spanish language. E.g:

  • Title = “Hola Mundo”
  • Body = “Esto es una prueba”

How can I do this?

Thank you so much.

8 – Does Drupal core Quick Edit function work for embedded entities?

I have a view which creates a block of User data related to the author of the node. The view display is a view mode of the User entity.

I see my entity when the block is placed on the node page; but there is no quick edit functionality. Is this expected behavior?

entities – Current Logged In user id not working properly Drupal 8

First, I want to disclose that I am a beginner in Drupal.

I’m having trouble getting to work the current logged in user id. I’m creating a menu link programmatically and adding the uri to go to ‘/user/userid/edit’. First of all, I should mention that it works at first, but then I get a bizarre behavior. I have two users for this test account. user1 has an id of 7, and user2 has an ID of 8. When I log in as user1, everything seems to be working properly, I hover over the menu link and it shows ID of 7. But then when I log out, and log in as user2 and when I hover over the menu link, I still see ID of 7 instead of ID of 8. I don’t know why that is.

I added a picture down below so that you can see visually of what I’m talking about. The arrow that is pointing to the ‘edit’ link under user2, that link always works and gets the user ID each and every time I log out and log in between the two users. I don’t mind putting that link in my menu, but I don’t know how.

enter image description here

The code below is where I’m creating the menu link and adding the ID of the “currently” logged in user.


namespace Drupalcurrent_user_idPluginMenu;

use DrupalCoreMenuMenuLinkDefault;
use DrupalCoreMenuStaticMenuLinkOverridesInterface;
use DrupalCoreSessionAccountInterface;
use DrupalCoreUrl;
use SymfonyComponentDependencyInjectionContainerInterface;
use DrupalCoreSessionAccountProxyInterface;
use DrupaluserEntityUser;
class UserOrdersMenuLink extends MenuLinkDefault {

  protected $currentUser;

  public function __construct(array $configuration, $plugin_id, $plugin_definition, StaticMenuLinkOverridesInterface $static_override, AccountInterface $current_user) {
    parent::__construct($configuration, $plugin_id, $plugin_definition, $static_override);

    $this->currentUser = $current_user;

  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static(

  public function getTitle() {
    return $this->t('Edit Profile');

  public function getUrlObject($title_attribute = TRUE) {

    $con = mysqli_connect("localhost","root","");
    if (!$con){die('Could not connect: ' . mysqli_error());}

    $sid = session_id();
    $userline = mysqli_query($con,"SELECT uid FROM sessions WHERE sid='$sid'");
    $u_row = mysqli_fetch_assoc($userline);
    $uid = $u_row('uid');

    //$current_user_ID = $this->currentUser->id();

    //$account = DrupaluserEntityUser::load(Drupal::service('session')->get('uid'));

    //$user = DrupaluserEntityUser::load(Drupal::service('session')->get('uid'));

    //$uid = $user->get('uid')->value;


    return Url::fromUri('internal:/user/' . $uid . '/edit');


The commented code is code that I tried; I got them in drupal stackexchange or stackoverflow basically where people were having similar issue as what I’m facing.

I tried connecting to the database and fetching out the user the old way, and even that failed. I get a ‘NULL NULL’

If you guys can help me out, I’d really appreciate it! Thank you!

database design – Whats the right table relationship for these entities?

I want to store all the data for the following entities:

A user can work in multiple projects and can have many roles, but only one role for a user should be allowed in each project, for example:

Jhon can work only as a developer in project #1 and can also work as a designer in project #2

I think the relationship should be:


Where the table User_Project has:

  • user_id
  • project_id
  • role_id

and the user_id,project_id combination is the primary key, and the role_id field is a foreign key to the roles table, where there is a row for each:

role_id role
1 project manager
2 developer
3 designer

is that the right way to describe the relationship between the entities ??

At first i thought about a many to many relationship for each the users – projects, projects – roles and user – roles, but i dont think it describes the “only one role in each project for a user”.

Entities vs. Services in domain driven design (DDD)

I wanted to get some feedback on the design of a chat application I recently developed. The application is written in PHP, but the language probably isn’t important here.

The main components are User, Conversation, and Message:

class User {
    public function getId(): int {}
    public function getUsername(): string {}
    public function getFirstName(): string {}
    public function getLastName(): string {}

    // token used with a 3rd party API for sending messages
    public function getToken(): ?string;
    // if a user doesn't have a token they can't be messaged
    public function isOnline(): bool {}

    public function __construct(int $id, string $username, ...) {}

class Conversation {
    public function getId(): int {}
    public function getUsers(): User() {}

    public function __construct(int $id, array $users) {}

class Message {
    public function getId(): int {}
    public function getText(): string {}
    public function getConversation(): Conversation {}
    public function getAuthor(): User {}

    public function __construct(int $id, string $text, Conversation $conversation) {}

I also have some services:

class MessageSender implements MessageSenderInterface
    private LoggerInterface $logger;

    public function send(Message $message): void {
        foreach ($message->getConversation()->getUsers() as $user) {
            if (!$user->isOnline()) {
                $this->logger->warn('User is offline and cannot be messaged');

            if ($user->equals($message->getAuthor())) {
                // continue; don't send messages to authors
            $messageData = (
                'to' => $user->getToken(),
                'from' => $message->getAuthor()->getUsername(),
                'text' => $message->getText(),
            // send the message through some external API

Most of the work is done through the MessageSender, but I’m wondering if the domain might be better encapsulated with something like this:

class Message {
    public function getId(): int {}
    public function getText(): string {}

    public function __construct(int $id, string $text, Conversation $conversation) {}

    public function send(MessageSenderInterface $sender, LoggerInterface $logger) {
        ... send logic in here

You can see that by moving the send functionality inside of the Message object we totally get rid of two exposed properties (getConversation and getAuthor are gone) and could effectively remove the service altogether. But as a result, the message object now knows about loggers and message senders, even if they are just interfaces.

What does DDD say about this? I tend to prefer exposing less data and like the encapsulation the second option provides.

terminology – In MVC, is the router considered one part of the controller? Or are they considered separate entities?

I’m learning to implement RESTful APIs, and the concepts of Controller and Router are common in many frameworks, along with the MVC pattern in general, so I’m encountering them everywhere.

From this question and googling around I understand that they are not the same thing, as they are responsible of very specific, and different, actions. But one thing isn’t clear: design-wise, is the router considered part of the controller?

In the mentioned question, one user comments:

You only need a model (database), a controller (which is the router), and the view (a page). That’s it. If you have a Router and a Controller then you’ve over complicated it and are just using the Router to pass data to a Controller. A Controller is a Router, but a Router is not a Controller.

I often see routers and controllers on the same file, but it’s very common to separate them in different files and/or directories. From this I understand that they are intimately related, but sometimes it’s better to separate them to implement separation of responsibilities, and to make our codebase modular and easier to maintain.

Also in the mentioned question, we can see answers considering the router part of the controller layer, but others treating it as a different entities. Both can make sense in a thought experiment:

  • Maybe you consider the router to exist before the MVC, as in one MVC per page. The router maps to the controller, but it’s not considered part of the controller itself.
  • Maybe you consider the router to be part of the controller, as in the whole webpage is one monolithic implementation of MVC. The router maps to the controller because one is part of the other.

This scenario is very subjective, but in the context of software architecture and design, is the MVC pattern more specific or clear about the roles and structure of routers and controllers?

In other words, is the router a module inside the controller, or is the router considered a separate actor (MVCR perhaps)?