Is this not yet ready in Drupal 7?
I have a custom action that should change the size of images using a field value, to scale them.
The custom action works, but the $node object is not there at all, as I even tried to resize the images using $node->nid (which should be an integer). The last idea was to do a query with the nid but of course it would be much better to have the value there.
I'm asking also because we still see
If possible, the owning $node object may also be available.
when you edit the custom action... maybe a D6 thing? Hopefully not...
Thanks!
Comments
Comment #1
ferrangil commentedI can access the data from "cck" fields doing this:
Not as easy as doing $node->my_field but works :)
Comment #3
d0t15t commentedso you include that in your image cache action?
Comment #4
denjell commentedI guess this shouldn't have closed. I would like an answer to this as well. Anyone with some positive experience in this regard?
Comment #5
fietserwinIf you are processing an image
- it may be a managed image file (in the database identified by a fid)'.
(=> if not, there will not be fields nor nodes.)
(the file name field is unique as well, thus there wont be multiple managed file records referring to it.)
- If it is a managed file there will be 0, 1 or more fields referring to the managed file.
- A field belongs to exactly 1entity.
- Thus there will be 0, 1, or more entities referring to the image.
- A node is an entity, an entity is not necessarily a node.
- Thus expecting a $node variable denies the D7 relational model behind images, managed files, fields and entities.
So I guess you may expect a managed file object, a set of fields and a set of entities. Currently you will only find the set of fields in the variable $fields (along some iamge properties like $width and $height). Documentation can be improved though.
Also note that the text effect (issue #1090312: Add text effect to D7) does more or less the same but does give you a $entity, This because often times there will only be 1 field and thus 1 entity be referring to the image. For these cases the $entity variable comes in handy. I will look into reusing that code with this effect.
Comment #6
mattbk commentedIs the code for getting the node title similar? Would one just replace
field_figure_escala_platewithtitleor is there a Drupal way to do this?Comment #7
fietserwinNo, title is not a field in D7 but a property of a node. So if you know that the entity will be of type ' node', You can use $entity->title.
Comment #8
dman commentedThat's a good explanation. In short, we often don't know where supporting data may come from, so it tries a few places and *may* come back with structured data which may be a variety of shapes :-)
Without the textactions around to really utilize the data extracted from the context - there has not been a lot of test cases for this particular feature in the upgrade. If text processing comes back on line, then this sort of data extraction will become a lot clearer.
The real pain is that you can't 'test' it on the sample image because the sample image has no node. So it requires intimate knowledge of internal structures (or lotsa debug logging) or a lot of guesswork to find a result. I can't suggest how that can be improved.
Comment #9
fietserwinThe code has been adapted to become more in line with the text effect that will be added as per #1090312: Add text effect to D7.
Changes:
This probably means that you will have to manually update all your current custom actions.
Comment #10
denjell commentedHey thanks. I am going to give it a try right now - and will report back.
Comment #12
attheshow commentedI was able to pull in the text information I needed to get the text from $node->title and another custom field using the following snippets:
If you have trouble figuring out what the exact array elements you need are, I recommend turning on the Devel module (so that you'll have access to the dsm() function) and then going temporarily into the image_effects_text.inc file and adding the line:
dsm($image_context);Into the image_effects_text_get_text() function. This will print out the contents of the $image_context array for you so that you can take a look at what you have to work with.
Comment #13
fietserwinOr you just look at the README.txt of the text effect module and see that this has already been done for you with some example data... As you seem to fetch only 1 title (of a node) I would like to suggest you to use (the easier and multilingual safe):
Comment #13.0
fietserwinEdit to include more information.