We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Possible to add a new hook?

Developer Preview

Brian Litzinger's avatar
Brian Litzinger
693 posts
6 years ago
Brian Litzinger's avatar Brian Litzinger

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);
   }
       
Kevin Cupp's avatar
Kevin Cupp
791 posts
6 years ago
Kevin Cupp's avatar Kevin Cupp

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.

       
Brian Litzinger's avatar
Brian Litzinger
693 posts
6 years ago
Brian Litzinger's avatar Brian Litzinger

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

       
Brian Litzinger's avatar
Brian Litzinger
693 posts
6 years ago
Brian Litzinger's avatar Brian Litzinger

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

if (!ee('LivePreview')->hasEntryData())
{
    return $result;
}
       
Brian Litzinger's avatar
Brian Litzinger
693 posts
6 years ago
Brian Litzinger's avatar Brian Litzinger

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

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.