You are here

function assets_pre_render_text_format in Asset 7

This function adds a settings required by assets

Parameters

$element: A fully populated form element to add the editor to.

Return value

array The same $element.

1 string reference to 'assets_pre_render_text_format'
asset_element_info_alter in ./asset.module
Implements hook_element_info_alter().

File

./asset.module, line 1180
Asset module.

Code

function assets_pre_render_text_format($element) {
  static $init = FALSE;
  if (isset($element['#format']) && $init === FALSE) {
    $init = TRUE;
    $asset_types = assets_get_types();
    $entity_info = entity_get_info('asset');
    $view_modes = $entity_info['view modes'];
    $config = array();
    $unavailable_creation_buttons = array();
    foreach ($asset_types as $name => $type_info) {
      $asset_type_params = array();
      $wysiwyg_modes = _assets_get_wysiwyg_modes($name);
      $modes = array();
      foreach ($wysiwyg_modes as $view_mode_name) {
        $modes[$view_mode_name] = $view_modes[$view_mode_name]['label'];
      }
      $asset_type_params['name'] = $type_info->name;
      $asset_type_params['icon'] = $type_info->icon;
      $asset_type_params['fields'] = _assets_get_overridable_fields($name);
      $asset_type_params['modes'] = $modes;
      $asset_type_params['accessEdit'] = asset_edition_access($name);
      $config[$name] = $asset_type_params;
      if (!asset_creation_access($name)) {
        $unavailable_creation_buttons[] = 'asset_' . $name;
      }
    }

    // Pass set of buttons to be hidden because of permissions.
    $config['removeButtons'] = $unavailable_creation_buttons;
    if (!asset_insert_asset_access()) {
      $config['removeButtons'][] = 'assetSearch';
    }
    drupal_add_js(array(
      'ckeditor' => array(
        'plugins' => array(
          'asset' => $config,
        ),
      ),
    ), 'setting');
  }
  return $element;
}