Question

I've edited my question as a response to the first commenter.

I'm new to PHP and Drupal templates and an not an experienced programmer.

My organization has events throughout the year. For each event we make recordings, speakers slides and other materials available to either anonymous users or just our members (a custom role). Each event has multiple files and whether they're made available to anonymous users or our members is made a file-by-file basis. So an event can have certain files available to anonymous users and others available only to our members.

We're using the ImageField Extended Fields module to add fields to file uploads and have a checkbox called "Make Public" along with "Description" and "Sort Order" (which I'm hoping can be used to order the files for display on the page... but that's not a priority). A content editor will check the box to make the file available to anonymous users but the default is just for our members.

The first commenter said the field contents look like a serialized array:

a:3:{s:11:"description";s:50:"text text text text text";s:19:"fapi_sort_order_key";a:3:{s:4:"body";s:1:"1";s:6:"format";i:0;s:5:"style";s:9:"textfield";}s:29:"workflow_fapi_make_public_key";i:1;}

I would like to evaluate this field to see whether the "workflow_fapi_make_public_key" portion is 1 or 0 and have the node.tpl.php file display differently depending on the results.

I started with

<?php if ($node->field_eli_event_files_data[0]) : ?>

then moved on to

<?php if (strpos($node->field_eli_event_files_data, '"workflow_fapi_make_public_key";i:0') !== FALSE) : ?>
  <h1>Hi there!</h1> 
<?php endif; ?>

. The latter statement always came up as false.

Any advice as to how this can be best accomplished would be greatly appreciated.

Thanks.

Was it helpful?

Solution

The value of the field that you have submitted is the serialized form found in the database, i.e. a string used to store the value of a complex variable - an array in this case - in a single database text field. You won't find this string anywhere in the node object. If you need more information on that, please refer to serialize() and unserialize() functions documentation in the php.net site.

If you need to test the value of workflow_fapi_make_public_key you will find it in $node->field_IMAGEFIELD_NAME[0]['data']['workflow_fapi_make_public_key'] (you should verify this via Devel module or another way to inspect the node's content).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top