Problem/Motivation

Content saved in the Youtube field type is currently not available for use in modules that rely on the Entity API for unified access to entity properties and fields. For example:

  1. Rules
  2. Search API

Proposed resolution

Follow the Entity API Handbook documentation for developers wishing to provide information about custom entity properties (including fields). This involves implementing hook_entity_property_info() to describe the getters, setters, permissions and schema that is used for the Youtube field type attached to various entity types.

Luckily the Entity API already provides some generic callbacks that can be used for accessing fields, so initial integration would be simple to accomplish and allow access through a generic getter callback very quickly and easily. With a generic getter callback, integration would be opened-up to:

Rules

The Rules module allows site administrators to define conditionally executed actions based on occurring events. Entity API integration for the Youtube module would allow Youtube field data to be used in Rules based event actions.

Search API

The Search API module provides a framework for easily creating searches on any entity known to Drupal, using any kind of search engine. By adding Entity API integration into the Youtube module, any entity fields that use the Youtube field type would then be able to be indexed by any search engine using the Search API.

Entity Metadata Wrapper

The most well-known and popular part of the Entity API is its entity metadata wrapper, which greatly simplifies the developer experience when accessing entity field data. By exposing the Youtube field type through Entity API you will be greatly simplifying its use for developers.

Example using Drupal 7.x core Field API:


$node = node_load($node_id);
$field_name = 'field_youtube_video';
$field_items = field_get_items('node', $node, $field_name);
$values = array();
if (is_array($field_items)) {
  foreach ($field_items as $delta => $item) {
    $values["{$field_name}_{$delta}"] = field_view_value('node', $node, $field_name, $item);
  }
}

Example using Entity API:


$node = node_load($node_id);
$field_name = 'field_youtube_video';
$node_metadata = entity_metadata_wrapper('node', $node);
$values = $node_metadata->{$field_name}->value();

Original report by andyg5000

Expose field property metadata to the entity api so that this module can be used by others that depend the metadata (ie: Rules, Search API).

Patch attached.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

guschilds’s picture

Could you provide more specific use cases for Rules, Search API, and/or other common cases that this would be helpful for? It would help me understand when/why it is needed and how I can test it. Thanks!

chOP’s picture

Issue summary: View changes
guschilds’s picture

Version: 7.x-1.0 » 7.x-1.2
Status: Needs review » Reviewed & tested by the community

Since #1 I have done a decent amount of work with the Entity API. Thanks to that and chOP's awesome update to the issue summary, I was able to properly test this patch. It worked as expected for me when using it with entity_metadata_wrapper(). I'm going to mark as RTBC and will get it committed into the repo in the near future. Thanks to both of you for your work on this!

RoSk0’s picture

Version: 7.x-1.2 » 7.x-1.x-dev

Confirming - patch adds support for metadata wrappers.

guschilds’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
Status: Reviewed & tested by the community » Needs work

Thanks for supplying the patch and testing. The patch has been committed to the 7.x-1.x branch and is now available in the 7.x-1.x-dev release.

I'm going to mark as "Needs work" and move the version to "8.x-1.x-dev" so we can determine if anything needs to be done to add such support to the 8.x version of this module before marking as Fixed.

Thanks again!

  • guschilds committed 272eec1 on 7.x-1.x authored by andyg5000
    Issue #2112603 by andyg5000, cHOP, RoSK0: Exposed YouTube field...
guschilds’s picture

Version: 8.x-1.x-dev » 7.x-1.x-dev
Status: Needs work » Fixed

I'm no longer going to keep this open for the 8.x branch. I've moved that work to a new issue: #2320305: [8.x blocker] Expose field data for Entity API.

To be clear: this work is complete and works as expected in 7.x.

guschilds’s picture

Status: Fixed » Closed (fixed)