I have many paragraphs on my Drupal site and I'm facing problems searching through them. Could you please add search functionality to this module?

CommentFileSizeAuthor
#2 3425503-2.patch4.26 KBcmarrufo

Issue fork paragraphs-3425503

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

vishal-Yaduvanshi created an issue. See original summary.

cmarrufo’s picture

Status: Active » Needs review
StatusFileSize
new4.26 KB

Hi @vishal-yaduvanshi

I have had the same problem and I think it would be a good idea to have a paragraphs type finder so I have made a patch that I think you could use.

vishal-ydv’s picture

hey @cmarrufo

thank you for your response, this functionality is very useful for me and the community of Drupal.

vishal-ydv’s picture

Status: Needs review » Reviewed & tested by the community
berdir’s picture

Status: Reviewed & tested by the community » Needs work

Looks intersting, but all non-trivial contributions must be merge requests now. A test would be great as well, but I can live without for non-critical functionality.

berdir’s picture

  1. +++ b/src/Controller/ParagraphsTypeListBuilder.php
    @@ -63,9 +73,123 @@ class ParagraphsTypeListBuilder extends ConfigEntityListBuilder {
    +
    +    $search_param = \Drupal::request()->get('search');
    +    $query = $this->getStorage()->getQuery();
    +
    +    if ($search_param) {
    +      $orCondition = $query->orConditionGroup()
    +        ->condition('label', $search_param, 'CONTAINS')
    +        ->condition('id', $search_param, 'CONTAINS');
    +      $query->condition($orCondition);
    +      $entity_ids = $query->execute();
    +      $filtered_array = [];
    +
    

    if we stick with a server-side implementation then this should override the getEntityListQuery() method, so we don't need to query and list twice.

  2. +++ b/src/Controller/ParagraphsTypeListBuilder.php
    @@ -63,9 +73,123 @@ class ParagraphsTypeListBuilder extends ConfigEntityListBuilder {
    +  public function buildForm(array $form, FormStateInterface $form_state) {
    +    $form['search'] = [
    +      '#type' => 'textfield',
    +      '#title' => $this->t('Search'),
    +      '#default_value' => \Drupal::request()->query->get('search'),
    +      '#description' => $this->t('Search paragraphs types by Label or ID'),
    

    would it make sense to default the focus on this field, then you can visit and type immediately.

    I'm also wondering if this should be a client-side functionality, similar to how \Drupal\views_ui\ViewListBuilder::render does it. That would require no reloads. would require to disable the pager, like views does.

cmarrufo’s picture

Assigned: Unassigned » cmarrufo

Hi @berdir,

I've uploaded an MR adding the filtering functionality like Views does. However, I haven't added any tests, although if it's strictly necessary, I could add them.

Thanks.

cmarrufo’s picture

Status: Needs work » Needs review

I forgot to add the template in paragraphs_theme(), sorry.