Hello,

I tried to directly access the value of a serial field with entity_metadata_wrapper.

But but unfortunately, the value seems to be missing when I try to get the info with $wrapper->getPropertyInfo().
All other fields of the node are normaly listed.

Any ideas what is going on?

Thanks

William

Comments

br0ken’s picture

Status: Active » Needs review
Issue tags: +entity, +entity_metadata_wrapper, +emw
StatusFileSize
new17.07 KB

Hi.

Helpful module, thanks to author.

Historically, that I use entity_metadata_wrapper() function to obtain the values of fields and this module is lacking a trifle for similar work with serial fields. Entity wrappers allowed only for fields that has the property_type in their definition in hook_field_info. My patch not only solves this problem, and also contains many improvements to the code style according to Drupal design standards.

P.S. Please, do not delay the consideration, because I like to use this module on my active project as "contrib".

br0ken’s picture

Also, tokens works fine now. No need to implement additional functionality, because we can use token of field name.

F.e.: when the name of field is field_serial, then it token will be [node:field_serial]. You can see this yourself by looking on Pathauto patters on admin/config/search/path/patterns

Due to that, think the documentation should be a little bit fixed.

br0ken’s picture

bot up

m1r1k’s picture

Status: Needs review » Needs work
+++ b/serial.inc
@@ -16,94 +15,93 @@
+  foreach ($query->addTag('node_access')->execute() as $record) {

Put adding tag outside of foreach.

  1. +++ b/serial.inc
    @@ -172,46 +166,58 @@ function _serial_generate_value($bundle, $field_name, $delete = TRUE) {
    +  $result = db_select('node', 'n')
    +    ->fields('n', array('nid'))
    +    ->condition('type', _anniversaries()->getContentTypeName())
    +    ->orderBy('nid')
    +    ->execute()
    +    ->fetchCol();
    

    Use EntityFieldQuery here and then node_load_multiple

  2. +++ b/serial.inc
    @@ -172,46 +166,58 @@ function _serial_generate_value($bundle, $field_name, $delete = TRUE) {
    +    ->condition('type', _anniversaries()->getContentTypeName())
    

    That's actually PHP 5.4+ requirements.

  3. +++ b/serial.inc
    @@ -172,46 +166,58 @@ function _serial_generate_value($bundle, $field_name, $delete = TRUE) {
    +  return $query->fields('i', array('bundle', 'field_name'))
    +    ->condition('f.type', 'serial')
    +    ->condition('i.deleted', 0)
    +    ->execute()
    +    ->fetchAll();
    +}
    

    Wrap all config queries with static cache

  4. +++ b/serial.install
    @@ -42,45 +32,40 @@ function serial_field_schema($field) {
    +    db_add_field($table, 'uniqid', $table_schema['fields']['uniqid']);
    
    +++ b/serial.module
    @@ -28,18 +26,19 @@ function serial_field_info() {
    -  if ($field['type'] == 'serial') {
    +
    +  if ('serial' == $field['type']) {
    

    Where is documentation about it? Or it is just your preferences?

  5. +++ b/serial.module
    @@ -116,39 +110,6 @@ function serial_node_type_update($info) {
    -// Tokens for fields are currently not supported - http://drupal.org/node/691078.
    -
    -///**
    -// * Implements hook_token_info().
    -// */
    -//function serial_token_info() {
    -//  $type = array(
    

    What is the reason of removing it? Add token implementations or leave it as it is :)

br0ken’s picture

Status: Needs work » Needs review
StatusFileSize
new16.85 KB
new1.61 KB

1. This is very moot point. I've leave this code as it was and just remove the unnecessary variable.
2. Query was replaced by node_load_multiple.
3. Chaining is allowed from PHP 5+. We're not call the method from instance directly.
4. No need to do that, because this function needs only for internal usage in different places.
5. This is a best practice that protects from wrong variable assignment in condition.
6. The commented code was removed because it is unnecessary. For all Drupal fields tokens generated automatically (see comment #2).

br0ken’s picture

StatusFileSize
new16.9 KB
new682 bytes

Found an issue while working with Features and Serial Field. Sometimes reverting operation is failed due to existing table for serial field.

colan’s picture

I'm one of the maintainers, and just reviewed the code. It looks great; thanks for working on this. As I don't have an environment set up to test this, let's wait for someone else to independently verify that it works. (If you know somebody, please ask him/her.)

Once it's RTBCed, we can commit.

gaydamaka’s picture

Hi, I looked the code and test the module. Errors in the module I have not found.

artem.vilkov’s picture

Hi guys, thanks for working on this.

I've installed the module and patch was applied successfully. Then I've created couple nodes with serial field in content type and test it accessibility by metadata wrapper. Everything works fine.

br0ken’s picture

Assigned: Unassigned » br0ken
Status: Needs review » Reviewed & tested by the community

Great, thanks guys. I'll do my first commit to this module ASAP.

  • BR0kEN committed 09a811d on 7.x-1.x
    Issue #2323277: Added checking of the table existence to "...
  • BR0kEN committed 12c8840 on 7.x-1.x
    Issue #2323277: Replaced SQL query by "node_load_multiple".
    
br0ken’s picture

Status: Reviewed & tested by the community » Closed (fixed)

Thanks all for work, new release (7.x-1.4) was done.