The shortcode api indicates there can be an 'attributes callback' for each shortcode. That callback is used by the Shortcode WYSIWYG module to render a form element to provide the attributes for each shortcode. None of these attributes are currently populated so there is nothing to see when you use the WYSIWYG module, and it takes some digging to even figure out what is expected. Populating these values will make it more clear how the module works and how it can be extended if you want to create custom shortcodes.

Attached is a patch that populates these values for each shortcode. When used with the Shortcode WYSIWYG module you will now see a little form element where you can provide each possible attribute.

In the process of doing this I found that the original code intention wouldn't work exactly as it should. The system is designed such that each form element would have a simple name like 'class' and use Drupal states system to hide or show itself only when its shortcode is selected. But if you have multiple items with the same name (like 'class') the states system doesn't correctly hide the duplicated elements. So I adjusted the original intention slightly and prefixed each attribute with the shortcode name, which makes each element unique.

For this to work right the Shortcode WYSIWYG module then needs to strip that prefix off before inserting the shortcode. I'm going to provide a patch on that module as well.

Other than that, this should be pretty self-explanatory.

CommentFileSizeAuthor
populate-attributes.diff19.49 KBKarenS
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

KarenS’s picture

See https://www.drupal.org/node/2312375 for the associated fix to Shortcode WYSIWYG.

Denes.Szabo’s picture

Assigned: Unassigned » Denes.Szabo

  • Denes.Szabo committed 0455a45 on 7.x-2.x
    Issue #2312353 by KarenS, Denes.Szabo: Populate attributes arrays
    
  • Denes.Szabo committed 522888d on 7.x-2.x
    Issue #2312353 by KarenS, Denes.Szabo: Populate attributes arrays
    
  • Denes.Szabo committed 69c47da on 7.x-2.x
    Issue #2312353 by Denes.Szabo: Clean up the code
    
  • Denes.Szabo committed 9970db4 on 7.x-2.x authored by KarenS
    Issue #2312353 by KarenS: Populate attributes arrays
    
  • Denes.Szabo committed cf53ab4 on 7.x-2.x
    Issue #2312353 by Denes.Szabo: Clean up the code
    
Denes.Szabo’s picture

Status: Needs review » Fixed

Dear KarenS, thanks for your work.

Your patch committed.

Status: Fixed » Closed (fixed)

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