encryption – Why don’t CAs advertize public keys of verified entities on a central location instead of giving out signed certificates?

If CAs (Certification Authorities) start advertizing public keys of verified websites via some API, browsers can simply query them for each domain instead of asking websites to give them certificates signed by CAs. If malicious entities try to intercept traffic and do the TLS handshake, they’ll fail because they won’t have the corresponding private key required to complete the process.

What’s the reason why this method is not preferred?

c++ – Efficient communication between entities using ECS via entt

To avoid confusion about the ECS terms I’ll use, I explain them here quickly. I use entt terminology and set-up my architecture like this:

  • Entity: is only an id (entt::entity)
  • Component: is a struct holding plain data (int, floats, etc.)
  • System: is a function looping over a family of components (using entt::registry.view)

In my game, I model a space ship that can have multiple engines. The engines apply a force on the ship each frame so the ship accelerates. I implemented it like the following:

Ship is an entity, Engine is an entity. Ship has the components AppliedForces, Mass and Velocity. Engine has the components Parent and Thrust. Parent is a component containing the parent’s id of the engine (in this case a ship entity).

I have two systems: ThrustSystem goes through all entities that have the components Thrust and Parent. It looks up the AppliedForces component of the parent and adds the thrust vector to it. Then the AccelerationSystem runs through all entities with the components AppliedForces, Mass and Velocity. It adds the applied forces to entity’s velocity. In code, it looks like this:


void ThrustSystem::update(entt::registry& entities)
{
  auto view = entities.view<Thrust, Parent>();
  for (auto (thrust, parent): view)
  {
    auto& applied_forces = entities.get<AppliedForces>(parent.id);
    applied_forces.vector += thrust.vector;
  }
}

void AccelerationSystem::update(entt::registry& entities, dt)
{
  auto view = entities.view<AppliedForces, Mass, Velocity>();
  for (auto (applied_forces, mass, velocity): view)
  {
    velocity.vector += applied_forces.vector * mass * dt;
  }
}

This works perfectly for me, the systems are decoupled and work independently from each other and I don’t experience any performance issues (I model max. 1000 ships with an average number of 4 engines each). So I will stick to this implementation in my current game.

But I am actually curious and I would like to learn more about the “correct” usage of ECS in game code: is this a recommended approach to gain high performances and avoid cache misses? This is my first project with ECS and I am not an expert in CPU stuff at all but naively-thinking I would say there are two “bottlenecks” in my code:

  • Look-up time for the AppliedForces component of the parent entity in ThrustSystem
  • The AppliedForces is probably further away from Thrust and Parent in memory. So I introduced a cache miss.

At first, are my assumptions correct? And if yes, how would one avoid these bottlenecks?

opengl – Data structure for collecting entities for instanced rendering

My game, a citybuilder, has many simple entities that rendered via glDrawArraysInstanced. A large city has over 600,000 entities, but most of those entities are one of a few hundred meshes. Every frame, I need a way to collect all those entities so that every entity with the same mesh, texture, and shader pass can be rendered with one draw call. Since my game thread is separate from my render thread, I currently use a data structure, which I call the draw buffer, to collect a plan for what order to draw things in.

This data structure has become a real problem. It’s essentially a three dimensional chain of pointers to dynamic arrays, with the first dimension being shader pass, the second mesh, and the third texture. Every frame, the game goes through all entities (which are not in any particular order), filters out the ones that aren’t in the view frustum, and inserts that mesh’s data into the data structure. The draw buffer takes up a lot of memory and is highly fragmented.

I feel like this isn’t the right approach, but I’m not sure what the right approach is. I’m trying to figure out if there is a way to do it without storing what I plan to do, but I do think that can be done without multiple passes on the entity list. Maybe I can keep a master version of the data structure without view frustum culling and compute view frustum culling somewhere else. Then I wouldn’t have to rebuild the data structure every frame. Instead I would have to update the data structure every time something is added or removed — fortunately entities never change shader pass, texture or mesh, so entities will always stay in the same place in the master data structure.

I hope this makes sense to someone because it barely makes sense to me. The question is, can I solve this problem with a better data structure, or should I consider a different approach entirely? Thanks for any advice you guys have.

entities – View with referenced nodes from field in the same paragraph possible?

I can not seem to figure out how to set up the correct contextual and relationship settings to accomplish the following:

I have a node with a paragraph named slides. In the paragraph slides there is an entity reference field named field_selected_content that references various other nodes on the site.

I have a view called Slider, which is then printed in the Slides paragraph template.

The problem is that the view collects all references from all over the site from the field in the paragraph – I only want the once referenced by that specific paragraph (or if that is not realistically possible, at least from the same parent node ID).

I’ve experimented both with a regular block view as well as a “paragraph view”. But as soon as I try to apply a contextual filter with ID provided by url no results are shown. That said, I don’t fully understand the whole relationship/contextual concept as it seems quite intricate so I might have overlooked something really obvious perhaps?

entities – Entity where member variable is different type than when serialized

Not entirely sure how to phrase this.

I’ve got a config entity that needs to store a block id. In my config I have the mapping set to a string for the id.
When I load the entity, I’d think it would be more convenient to load the id and have the variable be a block.

This would mean I would need to :

  • On load, set $this->block = loadblock($id)
  • On save, set config->block = $block->id()

I’m finding the saving of entities to be quite ‘magic’ and thus hard for me to figure out.

Schema:

myent.myent.*:
  type: config_entity
  mapping:
    display_block:
      type: string
      label: Display block

entity:

/**
 * @ConfigEntityType(
 *   id = "myent",
 *   ...
 *   config_export = {
 *     ...
 *     "display_block",
 *   },
 * )
 */
class MyEnt extends ConfigEntityBase {

  // This should be loaded as an entity, not a string.
  protected $display_block;

}

For the loading, I could just override __construct and use the loaded string to load up the entity but that feels very hacky. Plus then IDK how to save it properly when saving.

There is also the option of having a getBlockRaw and getBlock as two seperate options. Have a variable for the string and a non exported one for the loaded entity.

entities – Base table or view not found: 1146 Table ‘drupal8_formation.profiles’ doesn’t exist

i have this following error when i want to get access to the module ‘profile’:

SQLSTATE(42S02): Base table or view not found: 1146 Table ‘mydatabase.profile’ doesn’t exist: SELECT base_table.profile_id AS profile_id, base_table.profile_id AS base_table_profile_id FROM {profiles} base_table GROUP BY base_table.profile_id LIMIT 1 OFFSET 0; Array ( ) dans DrupalCoreEntityEntityStorageBase->hasData() (ligne 580 de /var/www/html/core/lib/Drupal/Core/Entity/EntityStorageBase.php).

can anyone help me please ?


<?php

namespace DrupalprofileEntity;

use DrupalCoreEntityContentEntityBase;
use DrupalCoreEntityEntityTypeInterface;
use DrupalCoreFieldBaseFieldDefinition;

/**
 * Defines the user entity class.
 *
 *
 * @ContentEntityType(
 *   id = "profile",
 *   label = @Translation("Profile"),
 *   handlers = {
 *     "list_builder" = "DrupalprofileProfileListBuilder",
 *     "route_provider" = {
 *       "html" = "DrupalCoreEntityRoutingDefaultHtmlRouteProvider",
 *     },
 *     "form" = {
 *       "default" = "DrupalprofileFormProfileEntityForm",
 *       "add" = "DrupalprofileFormProfileEntityForm",
 *       "edit" = "DrupalprofileFormProfileEntityForm",
 *       "delete" = "DrupalprofileFormProfileEntityDeleteForm",
 *     },
 *   },
 *   admin_permission = "administer",
 *   base_table = "profile",
 *   data_table = "profile_field_data",
 *   translatable = TRUE,
 *   entity_keys = {
 *     "id" = "profile_id",
 *     "label" = "last_name",
 *     "langcode" = "langcode",
 *     "uuid" = "uuid"
 *   },
 *   links = {
 *     "add-form" = "/profile/add",
 *     "canonical" = "/profile/{profile}",
 *     "edit-form" = "/profile/{profile}/edit",
 *     "delete-form" = "/admin/profile/{profile}/delete",
 *     "collection" = "/admin/profile",
 *   },
 * )
 */

/*
    Creation of the Profile entity class
*/
class Profile extends ContentEntityBase implements ProfileInterface {

  public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {

    $fields('profile_id') = BaseFieldDefinition::create('integer')
        ->setLabel('Profile ID')
        ->setReadOnly(TRUE)
        ->setSetting('unsigned', TRUE);

    $fields('langcode') = BaseFieldDefinition::create('language')
        ->setLabel('Language code');

    $fields('uuid') = BaseFieldDefinition::create('uuid')
        ->setLabel('UUID')
        ->setReadOnly(TRUE);

   // Field Gender
   $fields('gender') = BaseFieldDefinition::create('list_string')
      ->setLabel(t('Gender'))
      ->setDescription(t('The gender of the Profile entity.'))
      ->setSettings(array(
        'allowed_values' => array(
          'female' => 'female',
          'male' => 'male',
        ),
      ))
      ->setDisplayOptions('view', array(
        'label' => 'above',
        'type' => 'string',
        'weight' => -4,
      ))
      ->setDisplayOptions('form', array(
        'type' => 'options_select',
        'weight' => -4,
      ))
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE);
     // Field Firsnt_name
    $fields('last_name') = BaseFieldDefinition::create('string')
      ->setLabel(t('Last Name'))
      ->setDescription(t('The last name of the Profile entity.'))
      ->setSettings(array(
        'default_value' => '',
        'max_length' => 255,
        'text_processing' => 0,
      ))
      ->setDisplayOptions('view', array(
        'label' => 'above',
        'type' => 'string',
        'weight' => -5,
      ))
      ->setDisplayOptions('form', array(
        'type' => 'string',
        'weight' => -5,
      ))
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE);

     // Field First name
    $fields('first_name') = BaseFieldDefinition::create('string')
      ->setLabel(t('First Name'))
      ->setDescription(t('The first name of the Profile entity.'))
      ->setSettings(array(
        'default_value' => '',
        'max_length' => 255,
        'text_processing' => 0,
      ))
      ->setDisplayOptions('view', array(
        'label' => 'above',
        'type' => 'string',
        'weight' => -5,
      ))
      ->setDisplayOptions('form', array(
        'type' => 'string',
        'weight' => -5,
      ))
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE);
     // Field Birth Date
    $fields('birth_date') = BaseFieldDefinition::create('datetime')
      ->setLabel(t('Birth Date'))
      ->setDescription(t('The Birth DAte of the Profile entity.'))
      ->setSetting('datetime_type','date')
      ->setRequired(TRUE)
      ->setDisplayOptions('view', array(
        'label' => 'above',
        'type' => 'string',
        'weight' => -5,
      ))
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE);
     // Field Birth Date
    $fields('email') = BaseFieldDefinition::create('email')
      ->setLabel(t('Email'))
      ->setDescription(t('Your email.'))
      ->setRequired(TRUE)
      ->setDisplayOptions('view', array(
        'label' => 'above',
        'type' => 'string',
        'weight' => -5,
      ))
      ->setDisplayOptions('form', array(
        'type' => 'string',
        'weight' => -5,
      ))
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE);
    // Entity Created
    $fields('created') = BaseFieldDefinition::create('created')
      ->setLabel(t('Created'))
      ->setDescription(t('The time that the entity was created.'));
    // Entity Changed
    $fields('changed') = BaseFieldDefinition::create('changed')
      ->setLabel(t('Changed'))
      ->setDescription(t('The time that the entity was last edited.'));

    return   $fields;
  }
}

entities – Confused about Entity bundles

I’m trying to convert a Drupal 7 site to Drupal 9 before D7 reaches EOL, and I had a custom module that had a lot of custom tables defined in Hook Schema, that would be joined together in different ways to handle a multi-step form made with the ctools form wizard. This site was originally created in Drupal 6, and updated to Drupal 7 while doing the minimum changes to the custom modules, so it predates the concept of Entities. The database structure of those tables is normalized, in 3rd normal form, because if you flattened it, would your end with millions of rows with mostly redundant information. The problem was that those tables existed in their own microcosm, not accessible to the rest of the site.

I’ve decided to rebuild everything from the ground up when doing the site upgrade, and I’ve also decided to drupalize this so the contents of these tables can be accessed by regular views, avoiding content duplication. This means that every old table will have to have it’s own entity type. Fields will be basefields for performance, since I will need 50-100 fields in total, and every fiend added through the UI requires a join as far as I understand. If I need to add fields in the future, I will do it through a module update, not by adding them through the UI, so I don’t need the entities to be fieldable.

After giving you this context, my actual question is, if I will only ever need 1 type of every entity bundle, do I really need entity bundles? What would entity bundles do for me?

entities – The “yourtypeentity” entity type does not exist. dans DrupalCoreEntityEntityTypeManager->getDefinition()

i have followed this tuto “https://www.droptica.com/blog/how-create-custom-entity-drupal-8/” on the web , but i am facing this error “DrupalComponentPluginExceptionPluginNotFoundException : The “dictionary_term” entity type does not exist. dans DrupalCoreEntityEntityTypeManager->getDefinition() (ligne 150 de /var/www/html/core/lib/Drupal/Core/Entity/EntityTypeManager.php).”

can anyone help me please i am new on drupal 8

<?php
/**
 * @file
 * Contains Drupalcontent_entity_exampleEntityContentEntityExample.
 */

namespace DrupaldictionaryEntity;

use DrupalCoreEntityEntityStorageInterface;
use DrupalCoreFieldBaseFieldDefinition;
use DrupalCoreEntityContentEntityBase;
use DrupalCoreEntityEntityTypeInterface;
use DrupaluserUserInterface;
use DrupalCoreEntityEntityChangedTrait;

/**
 * Defines the ContentEntityExample entity.
 *
 * @ingroup dictionary
 *
 *
 * @ContentEntityType(
 * id = "dictionary_term",
 * label = @Translation("Dictionary Term entity"),
 * handlers = {
 * "view_builder" = "DrupalCoreEntityEntityViewBuilder",
 * "list_builder" = "DrupaldictionaryEntityControllerTermListBuilder",
 * "form" = {
 * "add" = "DrupaldictionaryFormTermForm",
 * "edit" = "DrupaldictionaryFormTermForm",
 * "delete" = "DrupaldictionaryFormTermDeleteForm",
 * },
 * "access" = "DrupaldictionaryTermAccessControlHandler",
 * },
 * list_cache_contexts = { "user" },
 * base_table = "dictionary_term",
 * admin_permission = "administer dictionary_term entity",
 * entity_keys = {
 * "id" = "id",
 * "uuid" = "uuid",
 * "user_id" = "user_id",
 * "created" = "created",
 * "changed" = "changed",
 * "pl" = "pl",
 * "en" = "en",
 * },
 * links = {
 * "canonical" = "/dictionary_term/{dictionary_term}",
 * "edit-form" = "/dictionary_term/{dictionary_term}/edit",
 * "delete-form" = "/dictionary_term/{dictionary_term}/delete",
 * "collection" = "/dictionary_term/list"
 * },
 * field_ui_base_route = "entity.dictionary.term_settings",
 * )
 */
class Term extends ContentEntityBase {

  use EntityChangedTrait;

  /**
   * {@inheritdoc}
   *
   * When a new entity instance is added, set the user_id entity reference to
   * the current user as the creator of the instance.
   */
  public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {
    parent::preCreate($storage_controller, $values);
// Default author to current user.
    $values += array(
      'user_id' => Drupal::currentUser()->id(),
    );
  }

  /**
   * {@inheritdoc}
   *
   * Define the field properties here.
   *
   * Field name, type and size determine the table structure.
   *
   * In addition, we can define how the field and its content can be manipulated
   * in the GUI. The behaviour of the widgets used can be determined here.
   */
  public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {

// Standard field, used as unique if primary index.
    $fields('id') = BaseFieldDefinition::create('integer')
      ->setLabel(t('ID'))
      ->setDescription(t('The ID of the Term entity.'))
      ->setReadOnly(TRUE);

// Standard field, unique outside of the scope of the current project.
    $fields('uuid') = BaseFieldDefinition::create('uuid')
      ->setLabel(t('UUID'))
      ->setDescription(t('The UUID of the Contact entity.'))
      ->setReadOnly(TRUE);

// Name field for the contact.
// We set display options for the view as well as the form.
// Users with correct privileges can change the view and edit configuration.
    $fields('pl') = BaseFieldDefinition::create('string')
      ->setLabel(t('Polish'))
      ->setDescription(t('Polish version.'))
      ->setSettings(array(
        'default_value' => '',
        'max_length' => 255,
        'text_processing' => 0,
      ))
      ->setDisplayOptions('view', array(
        'label' => 'above',
        'type' => 'string',
        'weight' => -6,
      ))
      ->setDisplayOptions('form', array(
        'type' => 'string_textfield',
        'weight' => -6,
      ))
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE);

    $fields('en') = BaseFieldDefinition::create('string')
      ->setLabel(t('English'))
      ->setDescription(t('English version.'))
      ->setSettings(array(
        'default_value' => '',
        'max_length' => 255,
        'text_processing' => 0,
      ))
      ->setDisplayOptions('view', array(
        'label' => 'above',
        'type' => 'string',
        'weight' => -4,
      ))
      ->setDisplayOptions('form', array(
        'type' => 'string_textfield',
        'weight' => -4,
      ))
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE);

// Owner field of the contact.
// Entity reference field, holds the reference to the user object.
// The view shows the user name field of the user.
// The form presents a auto complete field for the user name.
    $fields('user_id') = BaseFieldDefinition::create('entity_reference')
      ->setLabel(t('User Name'))
      ->setDescription(t('The Name of the associated user.'))
      ->setSetting('target_type', 'user')
      ->setSetting('handler', 'default')
      ->setDisplayOptions('view', array(
        'label' => 'above',
        'type' => 'author',
        'weight' => -3,
      ))
      ->setDisplayOptions('form', array(
        'type' => 'entity_reference_autocomplete',
        'settings' => array(
          'match_operator' => 'CONTAINS',
          'size' => 60,
          'placeholder' => '',
        ),
        'weight' => -3,
      ))
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE);

    $fields('created') = BaseFieldDefinition::create('created')
      ->setLabel(t('Created'))
      ->setDescription(t('The time that the entity was created.'));

    $fields('changed') = BaseFieldDefinition::create('changed')
      ->setLabel(t('Changed'))
      ->setDescription(t('The time that the entity was last edited.'));

    return $fields;
  }

}

getDefinition()" />

Own permissions for paragraphs and ECK entities in drupal 8

I am a newbie to drupal functions and module development. I have come quite far in my Drupal 8 development without needing to write much custom php code. However, I am using paragraphs and eck entities as referenced entities in content types. For users to be able to edit their own content, I need edit and delete permissions in paragraph and eck to apply to only own content. I looked up some hooks and wrote the below code in my theme file. It doesn’t work. Will appreciate any help in taking this to finish line.

  function THEME_entity_info_alter(&$entity_info) {
      $entity_info('contact_information_fields')('access callback') = 'THEME_ENTITYNAME_access';
    }
    
 
    function THEME_ENTITYNAME_access(DrupalCoreEntityEntityInterface $entity, $op, DrupalCoreSessionAccountInterface $account) {
      $user = DrupaluserEntityUser::load(Drupal::currentUser()->id());
      switch ($op) {
        case 'update':
        case 'delete':
          if ($entity->uid == $user->get('uid')) {
            return TRUE;
          }
          break;
      }
    
      return eck__entity_access($entity, $op, $account);
    }

8 – Override remove entities link on module uninstall page

When a module needs to be uninstalled, Drupal adds links indicating there is content associated with the module which should be deleted first and provides a link Remove module_name entities. This works fine for most modules, however we have a complex module that needs to perform clean up, is there a way to override this link and have it invoke a custom entity deletion method?

In our case the Remove links that are automatically added to the module uninstall page, don’t end up cleaning all items, and leave the site in bad state.

Possibly related to this question asked earlier “How to remove custom module provided entity instances by the time the module being uninstalled?”