You are here

function _linkit_build_insert_plugin_form_fields in Linkit 7.3

Append insert plugin form element to the profile form.

@TODO: Insert pluings should only be used when dealing with fields as it makes no sence to have them when using a wysiwyg editor.

Parameters

LinkitProfile $profile: A profile object contains all settings for the profile.

See also

linkit_profiles_form()

1 call to _linkit_build_insert_plugin_form_fields()
linkit_profiles_form in plugins/export_ui/linkit_profiles.inc
Linkit profile settings form.

File

plugins/export_ui/linkit_profiles.inc, line 282

Code

function _linkit_build_insert_plugin_form_fields(&$form, LinkitProfile $profile) {

  // Make a list of all insert plugins.
  $insert_plugins = array();
  foreach (linkit_insert_plugin_load_all() as $name => $plugin) {
    $insert_plugins[$name] = $plugin['name'];
  }
  $form['data']['insert_plugin'] = array(
    '#type' => 'fieldset',
    '#title' => t('Insert methods'),
    '#description' => t(''),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#tree' => TRUE,
  );

  // Settings for insert plugins.
  $form['data']['insert_plugin']['plugin'] = array(
    '#type' => 'select',
    '#title' => t('Insert plugin'),
    '#options' => $insert_plugins,
    '#empty_option' => t('- Select an insert plugin -'),
    '#default_value' => isset($profile->data['insert_plugin']['plugin']) ? $profile->data['insert_plugin'] : '',
    '#states' => array(
      'visible' => array(
        'input[name="profile_type"]' => array(
          'value' => LINKIT_PROFILE_TYPE_FIELD,
        ),
      ),
      'required' => array(
        'input[name="profile_type"]' => array(
          'value' => LINKIT_PROFILE_TYPE_FIELD,
        ),
      ),
    ),
  );
  $form['data']['insert_plugin']['url_method'] = array(
    '#title' => t("Insert paths as:"),
    '#type' => 'radios',
    '#title_display' => 'before',
    '#options' => array(
      LINKIT_URL_METHOD_RAW => t('Raw paths'),
      LINKIT_URL_METHOD_RAW_SLASH => t('Raw paths, with a slash (/) in the beginning.'),
    ),
    LINKIT_URL_METHOD_RAW => array(
      '#description' => t('This will insert Drupal internal paths like
         %example_link which is probably what you want if you are going to use
         this profile together with <strong>fields</strong>.
         <br/>If used in textareas, these paths typically need to be formatted
         using a input filter, but provides more flexibility in a multilingual
         site or when moving a site.', array(
        '%example_link' => 'node/123',
      )),
    ),
    LINKIT_URL_METHOD_RAW_SLASH => array(
      '#description' => t('This is the default behavior, it will insert paths
         like %example_link.<br/>These will work <strong>without the need for an input filter</strong>,
         but might fail after moving a site, or on multilingual sites.', array(
        '%example_link' => '/node/123',
      )),
    ),
    '#default_value' => isset($profile->data['insert_plugin']['url_method']) ? $profile->data['insert_plugin']['url_method'] : LINKIT_URL_METHOD_RAW_SLASH,
    '#description' => t('These will have no effect on already created links.'),
  );
  if (module_exists('path')) {
    $form['data']['insert_plugin']['url_method']['#options'][LINKIT_URL_METHOD_ALIAS] = t('Alias paths');
    $form['data']['insert_plugin']['url_method'][LINKIT_URL_METHOD_ALIAS] = array(
      '#description' => t('This will insert the alias for the result item.
        <br/>The paths will be run through the <em>url()</em> function.', array(
        '%example_link' => 'node/123',
      )),
    );
  }
}