Problem/Motivation

The sub fields aren't available using a standard hook_form_alter()

Proposed resolution

I propose adding a drupal_alter() to make the field ($element) available.

Remaining tasks

Please review and test forthcoming patch.

User interface changes

None

API changes

Add drupal_alter() to flickrfield_form_process_flickrfield()

Comments

lolandese’s picture

Hi,

flickrfield should be available to alter sub fields.

Please explain or provide an example or use case.

Assign to yourself if you intend to write a patch.

Patches will be reviewed promptly and will be committed with attribution upon reaching RTBC status.

Thanks.

joewhitsitt’s picture

Status: Active » Needs review
StatusFileSize
new379 bytes
joewhitsitt’s picture

Assigned: Unassigned » joewhitsitt

Sorry, didn't see your comment before I posted the patch.

Personally, we are using the field but simplifying it for our content editors by setting type and nsid access to false, altering the title/description for id. Ideally I am looking forward to this feature: https://www.drupal.org/node/1170010, but I think it would be nice to have going forward regardless.

lolandese’s picture

Nice.

To test and as an example for others that want to make use of this, could you provide the hook_flickrfield_process_alter() function that you defined in your custom module as well? Write in CAPS the custom bits that one needs to alter, like MYMODULE_flickrfield_process_alter().

After commit and a new stable release I will add your provided example to the module's Developer documentation at https://www.drupal.org/node/2289797.

Thanks.

joewhitsitt’s picture

An example of using the proposed drupal_alter():

<?php
function MYMODULE_flickrfield_process_alter(&$element) {
  // Remove access to all but the item id
  $element['type']['#access'] = FALSE;
  $element['nsid']['#access'] = FALSE;
  // Alter the item id's title and description
  $element['id']['#title'] = 'Flickr Photoset ID';
  $element['id']['#description'] = '<em>i.e. http://flickr.com/.../sets/<b>[photoset id]</b></em>';
  // Confirm the default value is set to photo set (id)
  $element['type']['#default_value'] = 'id';
}
?>

  • lolandese committed cbdc1dd on 7.x-1.x authored by jwhitsit
    Issue #2416565 by jwhitsit: flickrfield should be available to alter sub...
lolandese’s picture

Status: Needs review » Reviewed & tested by the community
Related issues: +#1170010: Parse the user id (nsid) and photo/set id from the Flickr page URL
StatusFileSize
new962 bytes
new54.21 KB
new40.57 KB
martin@martin-X501A1:~/www/brown/sites/all/modules/flickr$ git apply -v flickr-add_alter_hook-2416565-1.patch
Checking patch field/flickrfield.module...
Applied patch field/flickrfield.module cleanly.

Above example code has been put in a custom module. See attached zip file to be extracted in the module folder 'flickr'.

All works as expected. See attached screenshots of the modified field before and after enabling the custom module.

The provided example, although intended only to test the provided patch, can be used by those that are looking to simplify the Flickr Field. It has to be said that:

  • it removes the possibility to use the field to hold a single image (only sets)
  • it works nevertheless the default user ID that is used might not correspond with the 'owner' of the Flickr set. Even if a default user ID is unknown it works.

An excellent use case example of the function drupal_alter().

Thanks for contributing.

BEFORE:

BEFORE

AFTER:

AFTER

lolandese’s picture

Status: Reviewed & tested by the community » Fixed
lolandese’s picture

Added some documentation on this at https://www.drupal.org/node/2289797#field.

Feel free to correct grammar or improve readability over there.

Thanks.

Status: Fixed » Closed (fixed)

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

joewhitsitt’s picture

Status: Closed (fixed) » Active

@lolandese, just updated to 7.x-1.6 and saw that this drupal_alter() wasn't in there anymore. Is this a mistake or do you have a reason for taking it out?

lolandese’s picture

Use the dev for now. It should be pretty safe. That's where this is committed. 7.x-1.6 is from 2014-Jun-26. The commit was made February 20, 2015. A new stable version is upcoming, probably in a few weeks. See #2421343: What 'active' issues go in the next stable release?.

You can also patch the 7.x-1.6 version.

joewhitsitt’s picture

Status: Active » Closed (fixed)

Oh geez. Sorry, I didn't read the dates/version number correclty.