Comments

hgoto created an issue. See original summary.

hgoto’s picture

Status: Active » Needs review
StatusFileSize
new3.61 KB

Here is a patch for this feature.

How to test this patch:

  1. Enable Machine name module and Entity module.
  2. Create a content type with a machine name field like field_my_machine.
  3. Create a content of the type.
  4. Use entity metadata wrapper to use the field. The following is a sample code.

// set your node id for the node.
$nid = '3';

// You can get the value.
$wrapper = entity_metadata_wrapper('node', $nid);
$wrapper->field_my_machine->value();  // => you can get the value.
$wrapper->field_my_machine->info();  // => you can get the metadata info of the field.

// You can set a value.
$wrapper->field_my_machine = 'abc';
$wrapper->save();

// There's a validation on value assignments.
$wrapper->field_my_machine = '__';  => Error
$wrapper->field_my_machine = '%^&*'';  => Error

I'd like someone interested to review this patch. Thank you.

hgoto’s picture

Status: Needs review » Needs work
hgoto’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
manu manu’s picture

Status: Needs work » Reviewed & tested by the community

Using the patch from #2 and haven't found any issues.

Thanks!

manu manu’s picture

Status: Reviewed & tested by the community » Needs work

Spoken too quick. This work with nodes, not with other entities, eg: taxonomy terms.

This is because the validation_callback is using $parent->type->value() and not all entities have a type property.

You should use $parent->getBundle();

hgoto’s picture

Status: Needs work » Needs review
StatusFileSize
new3.61 KB
new496 bytes

@manu manu thank you for your review.

Surely, $parent->type->value() doesn't support entities other than nodes and it's better to replace it with $parent->getBundle().

I updated the patch and tested it in my local environment. I'd like someone to review this.

Status: Needs review » Needs work
manu manu’s picture

Thanks @hgoto, testing right now.

hgoto’s picture

@manu manu thank you!

Please wait a little. I didn't notice why the CI error causes until now. It's caused by the following line, I believe.


  $entity_type = $parent->info()['type'];

This line uses the returned array direct but this is not allowed in PHP with old versions.

As of PHP 5.4 it is possible to array dereference the result of a function or method call directly. Before it was only possible using a temporary variable.

As of PHP 5.5 it is possible to array dereference an array literal.

http://php.net/manual/en/language.types.array.php

I'm going to fix it.

hgoto’s picture

Status: Needs work » Needs review
StatusFileSize
new3.64 KB
new589 bytes

I've updated the patch with change for the point #12.

I hope this would fix the CI error...

manu manu’s picture

Status: Needs review » Reviewed & tested by the community

Tested by getting and setting a machine_name field on a taxonomy term and it works well.

Thanks @hgoto.

danrod’s picture

Closing this one, 7.x is deprecated for a while.

danrod’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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