You are here

public function TMGMTEntityDefaultSourceUIController::overviewSearchFormPart in Translation Management Tool 7

Builds search form for entity sources overview.

Parameters

array $form: Drupal form array.

$form_state: Drupal form_state array.

$type: Entity type.

Return value

array Drupal form array.

1 call to TMGMTEntityDefaultSourceUIController::overviewSearchFormPart()
TMGMTEntitySourceUIController::overviewForm in sources/entity/ui/tmgmt_entity_ui.ui.inc

File

sources/entity/tmgmt_entity.ui.inc, line 109

Class

TMGMTEntityDefaultSourceUIController
Abstract entity ui controller class for source plugin that provides getEntity() method to retrieve list of entities of specific type. It also allows to implement alter hook to alter the entity query for a specific type.

Code

public function overviewSearchFormPart($form, &$form_state, $type) {

  // Add search form specific styling.
  drupal_add_css(drupal_get_path('module', 'tmgmt_entity') . '/css/tmgmt_entity.admin.entity_source_search_form.css');
  $form = array();

  // Add entity type value into form array so that it is available in
  // the form alter hook.
  $form_state['entity_type'] = $type;
  $form['search_wrapper'] = array(
    '#prefix' => '<div class="tmgmt-sources-wrapper tmgmt-entity-sources-wrapper">',
    '#suffix' => '</div>',
    '#weight' => -15,
  );
  $form['search_wrapper']['search'] = array(
    '#tree' => TRUE,
  );
  $form['search_wrapper']['search_submit'] = array(
    '#type' => 'submit',
    '#value' => t('Search'),
    '#weight' => 10,
  );
  $form['search_wrapper']['search_cancel'] = array(
    '#type' => 'submit',
    '#value' => t('Cancel'),
    '#weight' => 11,
  );
  $entity_info = entity_get_info($type);
  $label_key = isset($entity_info['entity keys']['label']) ? $entity_info['entity keys']['label'] : NULL;
  if (!empty($label_key)) {
    $form['search_wrapper']['search'][$label_key] = array(
      '#type' => 'textfield',
      '#title' => t('@entity_name title', array(
        '@entity_name' => $entity_info['label'],
      )),
      '#size' => 25,
      '#default_value' => isset($_GET[$label_key]) ? $_GET[$label_key] : NULL,
    );
  }
  $language_options = array();
  foreach (language_list() as $langcode => $language) {
    $language_options[$langcode] = $language->name;
  }
  $form['search_wrapper']['search']['language'] = array(
    '#type' => 'select',
    '#title' => t('Source Language'),
    '#options' => $language_options,
    '#empty_option' => t('All'),
    '#default_value' => isset($_GET['language']) ? $_GET['language'] : NULL,
  );
  $bundle_key = $entity_info['entity keys']['bundle'];
  $bundle_options = tmgmt_entity_get_translatable_bundles($type);
  if (count($bundle_options) > 1) {
    $form['search_wrapper']['search'][$bundle_key] = array(
      '#type' => 'select',
      '#title' => t('@entity_name type', array(
        '@entity_name' => $entity_info['label'],
      )),
      '#options' => $bundle_options,
      '#empty_option' => t('All'),
      '#default_value' => isset($_GET[$bundle_key]) ? $_GET[$bundle_key] : NULL,
    );
  }
  elseif (count($bundle_options) == 0) {
    drupal_set_message(t('Entity translation is not enabled for any of existing content types. To use this functionality go to Content types administration and enable entity translation for desired content types.'), 'warning');
    unset($form['search_wrapper']);
  }
  $options = array();
  foreach (language_list() as $langcode => $language) {
    $options[$langcode] = $language->name;
  }
  $form['search_wrapper']['search']['target_language'] = array(
    '#type' => 'select',
    '#title' => t('Target language'),
    '#options' => $options,
    '#empty_option' => t('Any'),
    '#default_value' => isset($_GET['target_language']) ? $_GET['target_language'] : NULL,
  );
  $form['search_wrapper']['search']['target_status'] = array(
    '#type' => 'select',
    '#title' => t('Target status'),
    '#options' => array(
      'untranslated_or_outdated' => t('Untranslated or outdated'),
      'untranslated' => t('Untranslated'),
      'outdated' => t('Outdated'),
    ),
    '#default_value' => isset($_GET['target_status']) ? $_GET['target_status'] : NULL,
    '#states' => array(
      'invisible' => array(
        ':input[name="search[target_language]"]' => array(
          'value' => '',
        ),
      ),
    ),
  );
  return $form;
}