I'm trying to figure out the best, most user friendly way to integrate shortcode with the code editor and I think the best way is having a form where you set shortcode options and then the shortcode is inserted with proper settings and/or example HTML inside the shortcode.

I saw this piece of code:

 *   - settings callback: The name of a function that returns configuration form
 *     elements for the shortcode. TODO

So I guess someone has already started with this? Has any work been done on this yet?

Comments

jurriaanroelofs’s picture

now that I'm reading more into the code I see this refers to the settings at admin/config/content/formats/[format] but there is some code in the WYSIWYG module that seems related to this feature:

  foreach($shortcodes as $name => $shortcode) {
    if ($shortcode['attributes callback']) {
      $form[$name] = call_user_func_array($shortcode['attributes callback'], array(array(), $form_state));
    }
  }
jurriaanroelofs’s picture

Ok sweet I see this already pretty much works. Now I'll just add some code to support example code. In some wordpress WYSIWYG integrations the shortcode button will insert something like this:

[custom_list style="list-4"]

  • your list item
  • your list item
  • your list item

[/custom_list]

denes.szabo’s picture

How this issue? Could you write a small summary about it?

jurriaanroelofs’s picture

Status: Active » Closed (fixed)

Never mind this issue, it was about creating WYSIWYG editor integration but it already exists now.

BarisW’s picture

Title: Interactive form for shortcode WYSIWYG insertion » HOW-TO: Use an interactive form for shortcode WYSIWYG insertion
Category: feature » support
Status: Closed (fixed) » Active

I'm re-opening this issue. It is not clear how I can write my own shortcodes and provide a settings form in the WYSIWYG integration.
Can you describe how to use the 'attributes callback' in your own hook_shortcode_info() implementation?

BarisW’s picture

I figured it out, pretty easy to use!

<?php
'attributes callback' => 'my_settings_callback_function'
?>

And then a function that just returns a Drupal form:

<?php
function my_settings_callback_function(){
  return array(
    'title' => array(
      '#title' => t('Title'),
      '#type' => 'textfield',
    ),
    'color' => array(
      '#title' => t('Background color'),
      '#type' => 'select',
      '#options' => drupal_map_assoc(array('dark', 'light')),
      '#default_value' => 'dark',
    ),
    'align' => array(
      '#title' => t('Alignment'),
      '#type' => 'select',
      '#options' => drupal_map_assoc(array('left', 'right')),
      '#default_value' => 'right',
    ),
  );
?>

I'm leaving this active so it can be added to the README.txt first ;)

denes.szabo’s picture

Project: Shortcode » Shortcode for Wysiwyg
Issue summary: View changes

Moved to the shortcode_wysiwyg project.

shelane’s picture

This is great for attributes of the shortcode. How can we add an entry for the "text" that appears in the center of the shortcode as:
[myshortcode]defined as text in shortcode[/myshortcode]

shelane’s picture

Documentation on how to use the attribute callback is now provided as part of this module's documentation.

shelane’s picture

Status: Active » Fixed

Documentation is now provided.

If you have trouble understanding any part of the documentation, please notify those of us who work on this section and clearly explain what you don't understand and why. We're happy to hear from you. Your contribution helps everyone at Drupal!

shelane’s picture

Status: Fixed » Closed (fixed)