query data to drupal easily

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
vacho's picture

Hi guys

I have started to develop a module that allows to programmers, to collect data from drupal very easily. The ambition is then also able to easily enter datas.

THE MODULE INFO

Name:entities data

Url to test and contribute in drupal:https://www.drupal.org/sandbox/vacho/2368227

THE IDEA

Avoid writing long and complex code

$query = new EntityFieldQuery();

$query->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', 'people')
  ->propertyCondition('status', NODE_PUBLISHED)
  ->fieldCondition('field_ci', 'value', $ci, '=')
  ->addMetaData('account', user_load(1)); // Run the query as user 1.

$result = $query->execute();

if (isset($result['node'])) {
  $news_items_nids = array_keys($result['node']);
  $news_items = entity_load('node', $news_items_nids);
}
// and more... to really get datas...
//n-m relations???

Just do

$people = EntitiesData::getDatas('node', 'people', "name last_name", "ci=$ci");

Comments

Ever heard of the Helper module?

DYdave's picture

Hi @vacho,

Thanks very much for your contribution and letting us know about your module idea.

I just wanted to bring your attention on a project that could potentially achieve something a bit similar: the Helper module.
In particular it would seem to have a class for handling operations on entities, see the class EntityHelper in EntityHelper.php.
Now, I didn't check in detail whether the functions provided by your module already exist in Helper, but maybe you could take a closer look and if they don't exist yet you could perhaps discuss with module's maintainer whether they could be integrated, by posting a feature request in Helper's issue queue.

This would perhaps allow this functionality to be integrated as part of a greater whole, rather than just having a stand alone module with this feature only.
(Just a personal opinion)
I'm not completely sure, but I think there might be other similar modules with toolkits or libraries allowing more advanced operations on entities. You might as well be interested to take a closer look at those too and maybe do some more research.

Thanks again very much for your contributions, interest and involvement in the Drupal developers' community.
Cheers!

Checkout my sandbox EntityFieldQueryExtra

mikeytown2's picture

Created this for performance reasons. I need to pull a couple of field values every night from 20k users and created a module that does it really fast. Works how I wished EFQ would have always worked.
https://www.drupal.org/sandbox/mikeytown2/2209909

Thanks for replies

vacho's picture

I see de source code of "helper" module. This is a nice module. See this code extract of helper module EntityHelper.php

public static function loadSingle($entity_type, $entity_id) {
    $entities = entity_load($entity_type, array($entity_id));
    return reset($entities);
  }
public static function loadByCondition($entity_type, array $conditions) {
    $entities = entity_load($entity_type, FALSE, $conditions);
    return reset($entities);
  }
public static function updateFieldValues($entity_type, $entity) {
    list($id) = entity_extract_ids($entity_type, $entity);
    if (empty($id)) {
      throw new InvalidArgumentException(t('Cannot call EntityHelper::updateFieldValues() on an unsaved entity.'));
    }

    // Some modules use the original property.
    if (!isset($entity->original)) {
      $entity->original = $entity;
    }

    // Ensure that file_field_update() will not trigger additional usage.
    unset($entity->revision);

    // Invoke the field presave and update hooks.
    field_attach_presave($entity_type, $entity);
    field_attach_update($entity_type, $entity);

    // Clear the cache for this entity now.
    entity_get_controller($entity_type)->resetCache(array($id));
  }

Using this module it seems good to perform some tasks easier way to Entities. But no its the idea of "entities data" the idea is to reduce development time, the errors possibility and fatigue.

"Only one line of code to get datas"

However I should consider to join this project for what I would do. I'm not sure it's the idea of this project.

proceess of module

deepak_thorat's picture

What's your process to build to this module ??

Hi!!

vacho's picture

I'm not sure I understand your question correctly. Can you be more specific?

Contributed Module Ideas

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: