I have been trying to get the currently loaded page's property type.
I am building a website which has a lot of property types, different types of bundles for each and then the entities. Looking at the large number I decided to add the entities programitically. I managed to add all the entity types, but to m surprise i could find a way one can find the entity type id when there are no entities in the given entity type.
Can someone show me some way I can find the entity type id of the current uri?
I am thinking of using args() to get the value from the url and later finding the id from the title.

e.g
people (entity type) -> person (bundle) -> Foo Bar (Entity) or
music (entity type) -> compositions (bundle) -> Bar Foo (Entity)

I have already added people and music.

How do I continue to add my bundles? i.e person / compositions

Please help.

Comments

fmizzell’s picture

Hi @kalki2013. I am not clear on what you are trying to do, could you provide a sample url, and the kind of stuff that you would like to show at that url?

kalki2013’s picture

I have this huge list of entity types organised as
entity type -> Fields bundle -> Entity
I thought the the way to go would be inserting the entity types first, so i went ahead and added my top level e.g. people. People has a bundle in it called "profession" and this bundle the fields specific to person (other bundles under people will be ethnicity, gender etc).
I need to know the ID of "people" when i am on the url mydomain(dot)com/people so that i can go ahead and add the respective bundles to it. I wrote something in php which check for arg() and gets me the title of the entity type and went ahead with inserting the rows with sql queries, but i read around that it is not a good practice to us sql in drupal when there are so many api's available.
An example of the output url is mydomain(dot)com/people/profession/Bob_marley.
and if you are wondering where musician is, I have a field called type in the profession bundle from where I will fetch/display the profession types using a dropbox.

fmizzell’s picture

First of all you are using bundles in an unusual way, but that is fine, I don't thing there is a right or wrong way to use them, but it seems to me that the way in which you are using them will complicate your site. So with your url, you want to see bob_marley's profession, so you load the entity bob_marley (bob_marley is some sort of id) of type (bundle) profession. But then you will also have a bob_marley entity of type ethnicity, and then one of type gender. So if you ever wanted to to get all the info about bob_marley, you would have to load 3 different entities to get that info. This is definitely possible using EntityFieldQuery, but I just want to make sure that that is what you want. If I was modeling this stuff, I would have the entity_type people with only 1 bundle, and I would make profession, ethnicity, and gender taxonomy_vocabularies, that way I can connect those taxonomies to my people entity_type through a taxonomy_reference or entity_reference fields. Good luck, let me know if you need more assistance.

kalki2013’s picture

Bob Marley will be listen only in people(entity type)/person(bundle)/bob_marley
whereas other detais like example his ethnicity will be only a refrence to an entity called people/ehnicity/multiracial, another example of refrencing would be people/person/parents/norval_marley...
oops... as i was typing this out I am now wndering how do i refer backwards... i.e when i am on people/person/norval_marley how do i refer to person/people/child/bob_marley?
I am going ahead with structuring it the way you suggested.
Make an entity type people and a taxonomy term relation to his ethnicity.
I hope to get the url for ethnicity as people/person/ethnicity/multiracial showing the list of people/person in our case bob_marley. I have a hell lot of these refrences. My final question is? do you think it would be totally safe (simple referencing/structure etc. wise) to go ahead an have just 1 entity type foreach of these below.

* List Deleted *

Hope i was clear enough.
Thanks buddy

kalki2013’s picture

I am finally going ahead and adding all the entities. whether it is a person or a thing under
Entity Type (common) -> Bundle (topic) -> Entity (Bob Marley)
and referencing it from
Entity Type (people) -> Bundle (person) -> entity reference to common->topic->entity and
Entity Type (people) -> Bundle (profession) -> Entity (Musician)
and
Entity Type (people) -> Bundle (ethnicity) -> Entity (Multiracial)
This should solve the problem of having to add Boom Marley more than once right?

fmizzell’s picture

How you arrange things all depends on the details of your application. If the main object you are going to be working with is 'person', and the main way to identify a person is by their name (ej. Bob Marley), then it does not make much sense for the name information to be in a separate entity common:topic. Of course what I just mentioned about your application might be completely false. Mapping out the functionality of the site, and how data will be accessed and interacted with are a must before deciding what your data model will look like. I will have to say that what you are describing in #5 looks a lot cleaner than what was being proposed initially.

kalki2013’s picture

Thanks. Now coming back to my question. :)
I am going to allow people to create these categories (type->bundle->entity) and also allow them to add entities, But I need to know whether the entity type, bundle, entity has been added already. Specially if I am looking at urls like http://exampledomain.com/Bob_Marley
Would I have to write a regular SQL query for it?

fmizzell’s picture

You should be able to use EntityFieldQuery to make queries about your entities.

kalki2013’s picture

Somehow the plan flopped out. Started getting complicated as you said. Now went ahead with your way (taxanomy term reference). However another issue cropped up.
Now I made just 1 Entity Type called Common and a Bundle for it called Topic. In the the topic bundle I have a field called taxonomy term reference, this refers to the related term from taxonomies, it worked, but when i try displaying the list from the taxonomy term, not happening.
Eg.
Common/Topic/Drupal (the entity)
and
Computers/Software/ is the url from where the entity should get listed after i refer to it from the entity field right?
Not happening. :(

fmizzell’s picture

from ECK's admin UI you should have access to every entity created, the urls to view the entities should look like this: common/topic/[id]. ECK does not do anything special with fields, it simply uses the field apis to allow the user to edit, or display the fields. So, generally, I would say that any problem with fields is outside of ECK's hands. But check the manage display tab for your fields and make sure that you term reference field is not being hidden.

DamienMcKenna’s picture

Version: 7.x-2.0-rc2 » 7.x-2.x-dev
Assigned: kalki2013 » Unassigned

@kalki2013: you don't need to assign the issue to yourself :)