Skip to content

Instantly share code, notes, and snippets.

@jreviews
Last active November 18, 2019 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jreviews/4e20eee23fb0b258eae389064d998bd7 to your computer and use it in GitHub Desktop.
Save jreviews/4e20eee23fb0b258eae389064d998bd7 to your computer and use it in GitHub Desktop.
JReviews Developer Filter: Hide detail page map when street address is missing
<?php
defined('MVC_FRAMEWORK') or die;
/**
* Hide map in detail page when the listing doesn't have a street address
*/
function hide_map_noaddress($viewVars, $params)
{
$controller = $params['controller'];
$listing = $viewVars['listing'];
$hasAddress = !empty($listing['Field']['pairs']['jr_address']['text'][0]);
if ( $controller == 'com_content' && !$hasAddress )
{
$viewVars['show_map'] = false;
}
return $viewVars;
}
Clickfwd\Hook\Filter::add('before_theme_render_viewvars', 'hide_map_noaddress', 20);
@jreviews
Copy link
Author

jreviews commented Nov 3, 2019

To use this filter:

  1. Upload the above file to jreviews_overrides/filters
  2. If you use a different field than jr_address for street address, update the code to reflect the correct field name
  3. Add the line below to jreviews_overrides/filter_functions.php, if you are not using filters yet, read the documentation on Getting Started with JReviews developer filters

require_once "hide_map_noaddress.php";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment