Thread

Possible to add a new hook?

August 23, 2018 8:18pm

Subscribe [3]
  • #1 / Aug 23, 2018 8:18pm

    litzinger's avatar

    litzinger

    614 posts

    A customer pointed out that when using the Live Preview a Relationship field inside of Bloqs does not parse correctly. I have a feeling its b/c the conditionals in this method that are testing to see if it is Grid are not evaluating the way I need them to b/c… well… Bloqs isn’t exactly grid (though they share many things).

    I haven’t actually tested this to get it working, but I suspect that a hook just after the opening of the LivePreview check may suffice in what I need it to do. If I were to stub out a working example would EL be open to adding a hook?

    relationship_model.php line 196

    private function overrideWithPreviewData($result, $type, $fluid_field_data_id)
     {
      if (ee('LivePreview')->hasEntryData())
      {
           //
           // Possible to add a hook here that can return data and bypass the following stuff?
           //
    
       $data = ee('LivePreview')->getEntryData();
       $entry_id = $data['entry_id'];
    
       $channel = ee('Model')->get('Channel', $data['channel_id'])->first();
       $all_fields = $channel->getAllCustomFields();
    
       $rel_fields = $all_fields->filter(function($field)
       {
        return $field->field_type == 'relationship';
       })->pluck('field_id');
    
       if (/*true ||*/ $type == self::GRID)
       {
        $grid_field_ids = [];
    
        foreach ($all_fields as $field)
        {
         if ($field->field_type == 'grid'/* || $field->field_type == 'bloqs'*/)
         {
          $grid_field_ids[$field->getId()] = TRUE;
         }
         elseif ($field->field_type == 'fluid_field')
         {
          if ( ! empty($field->field_settings['field_channel_fields']))
          {
           $fields = ee('Model')->get('ChannelField')
            ->fields('field_id')
            ->filter('field_id', 'IN', $field->field_settings['field_channel_fields'])
            ->filter('field_type', 'grid')
            ->all();
    
           foreach ($fields as $grid_field)
           {
            $grid_field_ids[$grid_field->getId()] = TRUE;
           }
          }
         }
        }
    
        return $this->overrideGridRelationships($result, $data, array_keys($grid_field_ids), $fluid_field_data_id);
       }
  • #2 / Sep 05, 2018 10:12am

    Kevin Cupp's avatar

    Kevin Cupp

    744 posts

    Hi Brian, sorry for the delay! Wanted to discuss it internally first. Sounds like we’d be fine with a hook since there are already hooks to alter relationship stuff, but we’d want to see if you could put the hook towards the very end right before we return $result. Let us know if that works.

  • #3 / Sep 05, 2018 10:42am

    litzinger's avatar

    litzinger

    614 posts

    Yeah, I’ll look into that too. Thanks for the consideration.

  • #4 / Sep 06, 2018 5:44pm

    litzinger's avatar

    litzinger

    614 posts

    I noticed that the overrideWithPreviewData method could benefit from returning early. The additional nesting isn’t necessary.

    if (!ee('LivePreview')->hasEntryData())
    {
        return $result;
    }
  • #5 / Nov 23, 2018 9:18am

    litzinger's avatar

    litzinger

    614 posts

    Just closing this out… I don’t need a new hook. I can use the relationships_query hook.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases