Search

I’ve been using this quite often lately and this is certainly something that is useful for others:

Symphony offers a simple way to execute data source only if a required URL parameter is set. But from time to time you want to achieve the contrary and stop data source execution if a parameter is not set. With a small data source customization this is possible. Add this line to your grab() function replacing NameOfYourURLParam with the parameter name that should be checked:

if(!empty($this->_env['env']['url']['NameOfYourURLParam'])) return $this->emptyXMLSet();

Like so:

public function grab(&$param_pool=NULL){
    $result = new XMLElement($this->dsParamROOTELEMENT);

    if(!empty($this->_env['env']['url']['title'])) return $this->emptyXMLSet();

    try{
        include(TOOLKIT . '/data-sources/datasource.section.php');
    }
    catch(FrontendPageNotFoundException $e){
        // Work around. This ensures the 404 page is displayed and
        // is not picked up by the default catch() statement below
        FrontendPageNotFoundExceptionHandler::render($e);
    }           
    catch(Exception $e){
        $result->appendChild(new XMLElement('error', $e->getMessage()));
        return $result;
    }   

    if($this->_force_empty_result) $result = $this->emptyXMLSet();
    return $result;
}

This will return an empty XML element if the parameter title is set.

Finally change allowEditorToParse() to return false which will prevent the data source editor to edit your data source again and override your changes.

smart :)

It’s exciting to see this sort of functionality in the 2.1 sneak peek :)

It’s definitely going to be very useful.

Is this going to be added in 2.1 then? This is probably one of the best tips I’ve found on this forum to be honest, thanks to Brian pointing it out!

Brilliant!

This may be a stupid question… Does anybody know if this has been implemented as a feature?

It hasn't but shouldn't be too much work, and very beneficial IMO

Yep, definitely!

Brendan is preparing a general update to the Data Source editor logic and it should be easy to add this feature in this context. We are preparing everything on the interface side in 2.3, the programmatic changes are the next step planed after that, see #894.

This was just what I was looking for. Thanks Nils.

Can't wait for 2.3 with all this lovely functionality built into the data source builder!

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details