Problem/Motivation

The properties defined in data_entity_entity_property_info() don't have proper types assigned.

Proposed resolution

Reuse the code from the Entity module (_entity_metadata_convert_schema_type()) to assign the types.

Remaining tasks

Review patch #5

User interface changes

None.

API changes

Original report by @acouch

hook_entity_property_info() offers 'type' key which some modules use though was most likely not originally added to data_entity_entity_property_info() since this was added for feeds.

Missing the type throws an exception in search_api: http://drupalcode.org/project/search_api.git/blob/refs/heads/7.x-1.x:/in...

Comments

acouch’s picture

Status: Active » Needs review
StatusFileSize
new1.01 KB

Attached is a patch. I made the double and float number types as text to be conservative. I'm not sure what the repercussions for name an 'integer' for a number that has decimals etc.

joachim’s picture

Looks good, though is there any way we can make use of / extend _entity_metadata_convert_schema_type()?

manyk’s picture

Category: Task » Bug report
Issue summary: View changes

This really needs fixing. Search Facets/ Search API fails without this patch.

joachim’s picture

Status: Needs review » Needs work

See my comment #2.

das-peter’s picture

Status: Needs work » Needs review
StatusFileSize
new1.14 KB

How about this approach.
Looks like _entity_metadata_convert_schema_type() does pretty much what we need as base. We can decorate the data then with the metadata available.

das-peter’s picture

StatusFileSize
new6.37 KB

I just went totally crazy and extended the patch.
It enhances the integration with the entity module.

  • Recognition of entity relations. If a join points to another entity base table the property has the entity type as type.
  • Support for a name key for entities. Allows us to create exportable entities.
joachim’s picture

Status: Needs review » Needs work

> I just went totally crazy and extended the patch.

That's not really helpful I'm afraid... if patches are to be reviewed and committed, they need to stay focussed on the topic of the issue. Smaller patches that are easier to understand stand a better chance of getting committed. File new issues for further work!

das-peter’s picture

Issue summary: View changes
Status: Needs work » Needs review

f patches are to be reviewed and committed, they need to stay focussed on the topic of the issue

The patch in #5 still contains the minimal version - this one is good to and should be pretty easy to review.

das-peter’s picture

Working with the patched module revealed some issues when clearing / rebuilding caches.
Attached is an updated version of both patches.
The minimal version to re-use the schema property conversion from the entity module as well as the one that fully integrates with entity properties and provides abstract types as well.

joachim’s picture

StatusFileSize
new1.45 KB

This is more the approach I was thinking of -- using EntityAPI's _entity_metadata_convert_schema_type() to convert schema API types to EntityAPI property types.

I don't think we need to use the rest of EntityAPI's schema conversion: first, we don't put anything terribly useful into our hook_schema(), so having it processed and given back to us doesn't give us anything useful either. Second, as you found, there's caching issues.

One point against this approach is that _entity_metadata_convert_schema_type() is a module-private function (by the Drupal convention of starting with an underscore), so ideally shouldn't be used by other modules. However, I think at this stage we can say that Data module probably isn't going to make it out of alpha on D7, so I don't think we should worry too much about that ;)

theorichel’s picture

After applying this patch, I get this message:
Notice: Undefined property: SearchApiServer::$entity_type in entity_data_entity_load() (line 101 of /home/theorich/public_html/sites/all/modules/entity_data/entity_data.module).

Have no idea what it means and it may be a result of my being a search_api newbie

joachim’s picture

I was using SearchAPI with this patch to give it a spin and it was working ok.

Is there an 'entity_type' field on your data table? What type is is declared as in the table schema?

theorichel’s picture

Thanks.
Schema: The table consist of 9 fields of which the first 'IDAccess'is the primary key. The term entity is not mentioned here. But on the Tab Entity-type this same field ('IDAccess') is set as as Entity ID field. Table is defined as Entity Type.

The Tab Configure Entity Form marks all fields as required and one field ('Title') as label.

I have installed an Entity Browser-module and it tells me that the table is an entity type (Fieldable, 1 bundle, 0 view modes).

Hope this answers your question.

joachim’s picture

My patch removes the declaration of any properties for which we can't find a type, as they're technically broken anyway.

Can you check your entity properties before and after the patch? (Use Devel Contrib to inspect them.)

theorichel’s picture

I hope this is what you are looking for. 'Entity info' with Devel. With patch or without however makes no difference. This is the list:

label (String, 8 characters ) Foodnews
controller class (String, 20 characters ) DataEntityController
base table (String, 8 characters ) foodnews
fieldable (Boolean) TRUE
entity keys (Array, 4 elements)
bundles (Array, 1 element)
view modes (Array, 0 elements)
uri callback (String, 15 characters ) data_entity_uri | (Callback) data_entity_uri();
module (String, 11 characters ) data_entity
views controller class (Boolean) FALSE
static cache (Boolean) TRUE
field cache (Boolean) TRUE
load hook (String, 18 characters ) data_foodnews_load
translation (Array, 0 elements)
base table field types (Array, 9 elements)
schema_fields_sql (Array, 1 element)
configuration (Boolean) FALSE

joachim’s picture

Thanks, but , it's entity properties info I wanted, rather than entity info. You'll need Devel Contrib module for that: http://drupal.org/project/devel_contrib - use the -dev version.

theorichel’s picture

I am sorry. Have installed the Contrib -dev module (and its Generate partners), but I cannot find it. Entity Info yes, Entity Metadata yes, but not Entity Properties Info

theorichel’s picture

Ha it was part of the metadata (this is without patch):

comment (Array, 2 elements)
data_foodnews (Array, 1 element)
file (Array, 1 element)
node (Array, 2 elements)
search_api_autocomplete_search (Array, 1 element)
search_api_index (Array, 1 element)
search_api_server (Array, 1 element)
site (Array, 1 element)
taxonomy_term (Array, 1 element)
taxonomy_vocabulary (Array, 1 element)
user (Array, 1 element)

theorichel’s picture

This is the patched one. It looks like the patch made no difference
comment (Array, 2 elements)
data_foodnews (Array, 1 element)
file (Array, 1 element)
node (Array, 2 elements)
search_api_autocomplete_search (Array, 1 element)
search_api_index (Array, 1 element)
search_api_server (Array, 1 element)
site (Array, 1 element)
taxonomy_term (Array, 1 element)
taxonomy_vocabulary (Array, 1 element)
user (Array, 1 element)

FYI, a copy of my patched module:

<?php

/**
 * @file
 * Provides metadata for data entities.
 */

/**
 * Implements hook_entity_property_info().
 *
 * Allow modules to define metadata about entity properties.
 */
function data_entity_entity_property_info() {
  $tables = data_entity_get_entity_tables();
  $info = array();
  foreach ($tables as $table) {
    foreach ($table->table_schema['fields'] as $field_name => $field) {
      // Deduce the property type from the schema.
      if ($type = _entity_metadata_convert_schema_type($field['type'])) {
        $info['data_' . $table->name]['properties'][$field_name] = array(
          'label' => !empty($table->meta['fields'][$field_name]['label']) ? $table->meta['fields'][$field_name]['label'] : $field_name,
          'description' => 'Field of type ' . $field['type'] . '.',
          'type' => $type,
          'getter callback' => 'entity_property_verbatim_get',
          'setter callback' => 'entity_property_verbatim_set',
          'schema field' => $field_name,
        );
      }
     }
   }
   return $info;
}
joachim’s picture

Ok you've got the right one. Sorry for the confusion with the name of it.

What I need though is the sub-array inside that for your entity type's properties so:

Root -> your entity type -> properties

theorichel’s picture

I was so happy that I had found it that i turned blind. Well I suppose that this is what you were looking for:

properties (Array, 11 elements)
IDAccess (Array, 6 elements)
Kastnr (Array, 6 elements)
Titel (Array, 6 elements)
Aut (Array, 6 elements)
Jaar (Array, 6 elements)
Ref (Array, 6 elements)
Tref (Array, 6 elements)
Txt (Array, 6 elements)
Taal (Array, 6 elements)
feed_nid (Array, 4 elements)
feed_node (Array, 4 elements)

I could go deeper. These are the properties of IDAccess:

label (String, 8 characters ) IDAccess
description (String, 21 characters ) Field of type serial.
type (String, 7 characters ) integer
getter callback (String, 28 characters ) entity_property_verbatim_get | (Callback) entity_property_verbatim_get();
setter callback (String, 28 characters ) entity_property_verbatim_set | (Callback) entity_property_verbatim_set();
schema field (String, 8 characters ) IDAccess

theorichel’s picture

And this is the unpatched one:

properties (Array, 11 elements)
IDAccess (Array, 6 elements)
Kastnr (Array, 6 elements)
Titel (Array, 6 elements)
Aut (Array, 6 elements)
Jaar (Array, 6 elements)
Ref (Array, 6 elements)
Tref (Array, 6 elements)
Txt (Array, 6 elements)
Taal (Array, 6 elements)
feed_nid (Array, 4 elements)
feed_node (Array, 4 elements)

And again IDAccess:

IDAccess (Array, 6 elements)

label (String, 8 characters ) IDAccess
description (String, 21 characters ) Field of type serial.
type (String, 7 characters ) integer
getter callback (String, 28 characters ) entity_property_verbatim_get | (Callback) entity_property_verbatim_get();
setter callback (String, 28 characters ) entity_property_verbatim_set | (Callback) entity_property_verbatim_set();
schema field (String, 8 characters ) IDAccess

theorichel’s picture

That latter one was done with the patched file. I'll try again.

theorichel’s picture

properties (Array, 11 elements)
IDAccess (Array, 5 elements)
Kastnr (Array, 5 elements)
Titel (Array, 5 elements)
Aut (Array, 5 elements)
Jaar (Array, 5 elements)
Ref (Array, 5 elements)
Tref (Array, 5 elements)
Txt (Array, 5 elements)
Taal (Array, 5 elements)
feed_nid (Array, 4 elements)
feed_node (Array, 4 elements)

And IDAccess, which misses éntity property', and the others probably as well.

IDAccess (Array, 5 elements)

label (String, 8 characters ) IDAccess
description (String, 21 characters ) Field of type serial.
getter callback (String, 28 characters ) entity_property_verbatim_get | (Callback) entity_property_verbatim_get();
setter callback (String, 28 characters ) entity_property_verbatim_set | (Callback) entity_property_verbatim_set();
schema field (String, 8 characters ) IDAccess

joachim’s picture

I'm finding it hard to follow.

Does the patch cause any properties to vanish? You should be looking under root -> Your entity -> properties.

jerry’s picture

Status: Needs review » Reviewed & tested by the community

Working fine here. Let's RTBC it.

  • joachim committed 0b6bb90 on 7.x-1.x
    Issue #2058895 by das-peter, joachim, acouch: Added 'type' definition...
joachim’s picture

Status: Reviewed & tested by the community » Fixed

Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.