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. 関連モジュール タイトル
コンテンツの作成 8.9.x CKEditor CKEditor編集中の見た目をフロントと全く同様にする方法
コンテンツの作成 8.9.x node ノード保存時の前回値の参照方法
コンテンツの作成 7.38 CKEditor 突然GoogleMap内の経路がずれてしまった
コンテンツの作成 8.4x archiver zipファイル圧縮・解凍する方法
コンテンツの作成 7.15 Automatic_Nodetitles Automatic_Entity_Label ノード投稿フォームにタイトル入力フォームを表示しない方法
コンテンツの作成 7.26 Form Ajax 入力フォームで#ajax使用時、#default_valueを書き換えても反映しない
コンテンツの作成 8.9.x vim nkf ファイルのエンコーディングを確認、変更する方法
コンテンツの作成 7.34 Entityreference prepopulate 新規ノード作成時のリファレンス方法
コンテンツの作成 7.15 Mailhandler メールを通じてnodeの投稿をするには
コンテンツの作成 8.4x コンテンツ作成時のフォームレイアウトの変更
コンテンツの作成 8.9.x CSS キャプション付きの(右寄/左寄)画像を画像サイズを基準にきれいに表示する方法
コンテンツの作成 8.4x PhpSpreadsheet Excelを読み書きする方法
コンテンツの作成 6.x Views カルーセルのように回転するコンテンツを作りたい
コンテンツの作成 7.23 maxlength テキストフィールドの最大長のチェック&カウントダウン
コンテンツの作成 7.38 Webform Webformでテーブル形式にしたい
コンテンツの作成 7.38 node 代理投稿を可能にしたい
コンテンツの作成 7.50 Code per Node ページ毎にCSSやJSを設定したい
コンテンツの管理 8.6.x Commerce Commerce orderからすべての商品名を取得する方法
コンテンツの管理 6.x Views Flag Calendar 空き室予約のような仕組みは実現できますか?
コンテンツの管理 8.9.x 写真の変更を行いたい

ページ