Views Exposed Formの複数単語入力(textfield)をフォーム上だけ複数行入力(textarea)にする方法

カテゴリ Views Exposed Filter コアバージョン 8.4x 関連モジュール hook_views_pre_view

modles/custom/you_module/you_module.module

/**
 * Views Exposed form.
 *
 * @param $form
 * @param FormStateInterface $form_state
 * @param $form_id
 */
function your_module_form_views_exposed_form_alter(&$form, FormStateInterface $form_id) {
  switch ($form['#id']) {
    case 'your_form_id':
      $form['field_xxxxx']['#type'] = 'textarea';
      $form['field_xxxxx']['#rows'] = 5;
      break;
  }
}
/**
 * Views pre view.
 *
 * @param \Drupal\views\ViewExecutable $view
 * @param $display_id
 * @param array $args
 */
function your_module_views_pre_view(ViewExecutable $view, $display_id, array &$args) {
  if ($view->id() == 'your_view_id' && $display_id == 'your_display_id) {
      $value = \Drupal::request()->query->get('field_xxxxx');
      if (!empty($value)) {
        $value = trim(preg_replace('![\r\n]+!', ' ', $value));
        \Drupal::request()->query->set('field_xxxxxx', $value);
      }
    }
  }
}

OTHER FAQ

Drupal開発・運用の疑問/質問の答えはここに

無料ユーザー登録すると質問できます。

カテゴリ降順で並び替える Core Ver. 関連モジュール タイトル
コンテンツの作成 7.50 Expanding Textareas Textareaフォームの行サイズを自動調整するモジュール
コンテンツの作成 7.15 Darty Form 編集ページでの操作ミス
コンテンツの作成 7.15 Form API Validation フォームの入力内容を細かくチェックしたい
コンテンツの作成 8.4x node node保存前に色々やる方法
コンテンツの作成 8.9.x node ノード保存時の前回値の参照方法
コンテンツの作成 8.4x json jQueryにjsonで渡す方法
コンテンツの作成 6.x Insert Block ブロックの内容を本文中に表示するには?
コンテンツの作成 7.38 Webform Webformでテーブル形式にしたい
コンテンツの作成 8.4x archiver zipファイル圧縮・解凍する方法
コンテンツの作成 8.9.x vim nkf ファイルのエンコーディングを確認、変更する方法
コンテンツの作成 7.38 node 代理投稿を可能にしたい
コンテンツの作成 7.34 CCK ノード入力フォームへパラメータを渡す
コンテンツの作成 7.26 PHP ノード内の一部(フィールド)を変更する
コンテンツの作成 8.9.x CSS キャプション付きの(右寄/左寄)画像を画像サイズを基準にきれいに表示する方法
コンテンツの作成 7.15 Automatic_Nodetitles Automatic_Entity_Label ノード投稿フォームにタイトル入力フォームを表示しない方法
コンテンツの作成 7.34 Entityreference prepopulate 新規ノード作成時のリファレンス方法
コンテンツの作成 7.31 CKEditor CKEditorの新規生成ダイアログ内の初期値の変更
コンテンツの管理 7,51 Views Data Export Views Data ExportでCSVデータが欠けてしまう
コンテンツの管理 7.16 PHP 好きなところにノードを埋め込みたい
コンテンツの管理 8.6.x Commerce Commerce orderからすべての商品名を取得する方法

ページ