You are here

function entity_embed_pre_render_text_format in Entity Embed 7.2

Same name and namespace in other branches
  1. 7 entity_embed.module \entity_embed_pre_render_text_format()

Process text format elements to load and attach assets.

1 string reference to 'entity_embed_pre_render_text_format'
entity_embed_element_info_alter in ./entity_embed.module
Implements hook_element_info_alter().

File

./entity_embed.module, line 613
Provides a CKEditor plugin and text filter for embedding and rendering entities.

Code

function entity_embed_pre_render_text_format($element) {
  if (!isset($element['format'])) {
    return $element;
  }
  $field =& $element['value'];
  if (!isset($field['#value'])) {
    return $element;
  }

  // Add user-defined buttons.
  $embed_buttons = entity_embed_embed_button_load_all();
  $buttons = array();
  foreach ($embed_buttons as $embed_button) {
    $buttons[$embed_button->name] = array(
      'id' => check_plain($embed_button->name),
      'name' => check_plain($embed_button->name),
      'label' => check_plain($embed_button->button_label),
      'entity_type' => check_plain($embed_button->entity_type),
      'image' => check_plain(_entity_embed_button_image($embed_button->button_icon_fid)),
    );
  }
  $element['#attached']['library'][] = array(
    'dialog',
    'drupal.dialog.ajax',
  );
  $element['#attached']['js'][] = array(
    'data' => array(
      'entity_embed' => array(
        'DrupalEntity_dialogTitleAdd' => t('Insert entity'),
        'DrupalEntity_dialogTitleEdit' => t('Edit entity'),
        'DrupalEntity_buttons' => $buttons,
      ),
    ),
    'type' => 'setting',
  );
  return $element;
}