c++ – Why is an external template redeclared as a “different kind of entity”?

So I’m trying to share a templated global variable between translational units.

There is a common strategy to do this for functions where you have one header declaring/implementing the template and second C++ file that explicitly enumerates all arguments to actually generate the code for the linker.

I’m getting some strange error when extending this approach to templated structures. Does anybody know what the error means and which kind of entity is “declared”?

template<typename T>
struct PoolType
    void do_something()


template <class T>  extern PoolType<int> pool; //Suppoedly can live in another TU
//In some other file
PoolType<int> pool;

// template <class T>  PoolType<int> pool; //works fine but limited to one TU
int main ()


 error: 'PoolType<int> pool' redeclared as different kind of entity

on godbolt

entities – Validation on custom entity edit form

I have a custom entity where, instead of using the usual way of specifying edit form options with setDisplayOptions('form' and relying on ContentEntityForm to create my edit form for me, I have to make my own form in buildForm() (I have Ajax interactions between the fields that the stock from can’t provide). It works all right, just that I can’t trigger validation as with the stock form. The constraints are there and if I override:

public function validateForm(array &$form, FormStateInterface $form_state) {
  $entity = parent::validateForm($form, $form_state);
  $violations = $entity->validate();
  foreach ($violations as $v) {
  return $document;

the validation errors are in fact found and listed, just the form won’t display the usual red warnings, keeping the user from going on. Can I reconcile the custom form building with the automatic validation?

views – How can I see all the places an asset or entity is referenced?

In D8 there are some related modules you might want to check out:

In D7 there are some modules you might check and see if they have D8 plans:

There are open issues you may contribute to about this:

Create Views listing back-references

You’ll probably have to create a new View for each of the bundles you’re using references on (Content, Taxonomy term, File, Comment etc).

The key is to be aware of your project structure, to know where all of the reference fields are. So check your “Manage fields” pages everywhere for reference fields, and note what they reference. Then create a back-reference map from that info so you know which Views you need to create.

You may end up with less Views depending on your structure, you’ll need as many as there are entity types that are being referenced. Then if more than one type references it you can use Relationships to add them to the same view. This way you could have taxonomy terms type View that lists all Content and Files that are tagged with it.

Which Relationships and (Contextual) filter exactly needs to be used depends on the particular structure you have. You can use an Exposed filter instead of a Contextual if it’s just a tool to check references, but if you want to display a Block on relevant (Edit) pages that would automatically show what references this (smart) then you need the Contextual.

For example, if you have articles referencing other articles through Entity reference field:

  1. Create View with Block display listing articles
  2. Add the Contextual filter for that Entity reference field:
    When the filter value is NOT available
    Provide default value
    Content ID from URL
    When the filter value IS available or a default is provided
    Specify validation criteria
    Hide View if the argument doesn’t validate, or some other options that makes sense to you.
  3. Place the Block on article pages, or article edit pages, adjust Node from URL and other Block options.

The block will show if there are any articles that reference the one you’re viewing.

Other types of connections will require similar or other types of Views configuration.

domain driven design – Should an Use Case method receive a “pre-filled” entity or a DTO as a parameter?

I’m building a use-case for creating blog posts, at first I thought of using an entity as a use-case parameter, and this entity would be created by the layer that calls Use Case, in my case a controller.



public function createPost(request: Request): void {

  const imagesToUpload: string() = request.files('images');

  try {

    const PostEntity = new Post(..., imagesToUpload);
    const createdPost = this.createPost.create(PostEntity)

  } catch (exception) {

Use Case:

export default class CreatePost {

  private PostRepository: PostRepository;
  private StorageAdapter: StorageAdapter;

    PostRepository: PostRepository,
    StorageAdapter: StorageAdapter
  ) {
    this.PostRepository = PostRepository;
    this.StorageAdapter = StorageAdapter;

  public create(Post: Post): PostId {

    let uploadedImages: string();

      const images = Post.getImages()

      if (images.length > 0) {
        // upload images
          (image) => uploadedImages.push(this.StorageAdapter.upload(image))

    // imutability broken

    return this.PostRepository.create(Post)

Some problems I noticed:

1 – My Entity is being created on the controller without an ID

Although I could inject a repository or even directly use a factory to generate a PostId, it doesn’t seem right for an outer layer to communicate directly with an inner layer, although I understand that it’s okay for the infrastructure to know the domain.

2 – My entity is immutable, but some information is only available after some actions have taken place in my Use Case, such as the return of uploaded images URLs, so my entity may start with an invalid state (no images)

In this scenario where I’m breaking my entity’s immutability, and initially creating it without an ID, does it make sense to use a DTO as a Use Case parameter?

2.2 – if I use a DTO, wouldn’t the Use Case layer be coupled to the DTO, knowing its properties, getters, etc? or is it “OK” to create a specific DTO for this Use Case layer? such as: CreatePostDTO

8 – Access a user entity reference in a commerce-product template file

I have a field_intervenantfield which contains a user entity reference.
In the commerce-product template file, I want to access the description field of each intervenant.

How can I achieve it?

I tried reading the following values, but none of them returns what I am looking for.

  • product.field_intervenants.entity.field_description
  • product.field_intervenants.0.entity.field_description
  • product_entity.field_intervenants.0.entity.field_description
  • product_entity.field_intervenants.field_description
  • product_entity.field_intervenants.field_description.value

Do I need to loop through it, or am I missing something else?

c# – How to call a stored procedure that returns a list using .net core entity framework

I am migrating a .net framework project to .net core. In my .net framework code I call a stored procedure and it returns a list in a datatable:

 DataTable dt = new DLDistinctWarehousePackingOperation().CreatePacking(packingId, userId, 
 previousOrderId, totalAwaitingOrdersAllowed);
        List<int> items = new List<int>();
        foreach (DataRow dr in dt.Rows)
        return items;

This is the .net core code I have come up with untill now:

List<int> items = dbContext.FromSql("CreatePacking")
            .Select(t => new List<int> { t.OrderId.Value })

But it doesn’t work. How can I return a List – or does it have to be converted into a class instead? Thanks in advance.

entities – How do I get JSON data from a custom entity

I would like to GET JSON data from drupal 8 custom entity.
I am using ubuntu 14.04 and vagrant.
For that i have done these steps.

I have taken reference to Create drupal 8 custom entity from this link.

Enable this modules:

  • HAL – Core module
  • HTTP Basic Authentication -Core module
  • RESTful Web Services – Core module
  • Serialization – Core module
  • Restui – Contributed module

RESTui Configuration:

Permissions given for Rest full web services
enter image description here

Postman Plugin is integrated in to chrome.
below settings is done for postman.
enter image description here

Above steps i have done to GET JSON from custom entity but getting error in postman. Any suggestion or starting point will help for me.

Interestingly when i perform similar steps for drupal 8 node entity i am able to GET JSON data.

enter image description here


hooks – import multi-value from csv into entity reference field from a field collection

I posted this question at https://stackoverflow.com/questions/39234531/import-multi-value-from-csv-into-field-collections but I have not got any replies yet. Below is the summary:

I have a simple csv file with 3 columns: NID|Key|List; where NID is the node id and Key was the unique value used to add field collections to the respective node. “List” is a multi-value field separated by “;”.

Example (csv file):

Field collection has an entity reference field to a taxonomy plus other fields.

Field Collections:
Field1: text;
Field2: Term Reference;
Field3: Entity Reference; <-- importer/tamper not working!

The field collection fields were mapped correctly, except for the field that was an entity reference to a taxonomy. I configured Feeds Tamper with the Field Collection Feeds module but the entity reference list was not imported.

Does anyone has experience (suggestions) importing a multi-value field from a csv file into an entity reference field within a field collection?

entity system – How “smart objects” are implemented and actually work?

I’m drafting my game and implementing small stuff in it, but hit a roadblock. You see, for my game I would like for different items to behave the same or to share behavior, for instance, some items can be picked up and dropped to the floor, some items can get damaged and be repair while some only can get damage (the player cannot repair the item), some items can be use for a variety of different purposes (fire arms as weapons, frying pan as cooking tool and as a weapon), some items can get wet while others can get wet, catch fire and spread it further (or not; this is a reference to systemic games) and so on.

In my mind, the behavior must exist in the object and be abstracted from the player/AI/Other items nevertheless I’m lacking experience on how to go about this and I think that beside implementing a behavior there must exist also code that knows how to interact with such behavior, but this approach feels odd IMHO. In any case, I was asking around and The Sims was thrown in a reply, searching on the web found Living with The Sims’ AI: 21 Tricks to Adopt for Your Game, the trick 5 reads:

Each object has a public interface that broadcasts its functionality
to actors in the game. This is called advertising data in The Sims,
and contains a list of possible actions and what motives they satisfy.

If reading this correctly, it means that “smart objects” have a standard interface that actors can access to, right? My guess is that this interface covers everything behavior/systemic-wise that could happen in the game and the “actors” have code implemented that allow them to make use of this advertised interface, right?

Using Filter by an entity reference view with Rewrite Results gives “there are no entities matching” error

I’m using Drupal 9.2.
I have created entity reference views and use them as filter for entity reference fields (autocomplete widget).
When I’m using only “Content: Title” field everything works as expected. When using more fields either hidden (rewriting Title) or visible, I get “There are no entities matching (my selection)” error on save.

Does anybody have any idea why this is happening or how to debug?