mazedigital / association_output

Association Output for Symphony: Inline XML
MIT License
5 stars 4 forks source link

Setting included elements dynamically #1

Closed nilshoerrmann closed 10 years ago

nilshoerrmann commented 10 years ago

This is question for @brendo:

For the inline output of associated entries I'll add a few settings the Data Source file:

    public $dsParamINCLUDEDASSOCIATIONS = array(
        'festival' => array(
            'section_id' => 8,
            'field_id' => 58,
            'elements' => array(
                'anfang',
                'ende'
            )
        )
    );

This information is used to dynamically create a custom Data Source to fetch the needed entries, see https://github.com/hananils/association_output/blob/master/extension.driver.php#L67-L75:

    private function fetchAssociatedEntries($settings, $entry_ids = array())
    {
        $datasource = DatasourceManager::create('associations');
        $datasource->dsParamSOURCE = $settings['section_id'];
        $datasource->dsParamFILTERS['system:id'] = implode($entry_ids, ', ');
        $datasource->dsParamINCLUDEDELEMENTS = $settings['elements'];

        return $datasource->execute();
    }

The problem is that $datasource->dsParamINCLUDEDELEMENTS = $settings['elements']; doesn't have any effect. If I print $datasource before execution, I'll see that all settings are in place correctly, still the Data Source doesn't return any elements. If I set the same elements in the dummy Data Source file data.associations.php directly, it works though.

Any idea what's going on here, what I'm doing wrong here?

brendo commented 10 years ago

Hmm, can you verify what getSource is returning? I'm wondering if this function is returning nothing.

What do I have to do to get this environment setup locally? Just the Symphony integration branch?

nilshoerrmann commented 10 years ago

Yes, integration + this extension.

You'll have to add and adjust the additional setting to a DS with an associative field in the output. I've used a select box with dynamic values for testing.

nilshoerrmann commented 10 years ago

I just pushed a few changes to the repo: associations can now be included in the DS editor directly.

The issue mentioned above still exists. If I print the Data Source before execution, I get the following output (showing the included elements correctly:

datasourceassociations Object
(
    [dsParamROOTELEMENT] => associations
    [dsParamPAGINATERESULTS] => no
    [dsParamSTARTPAGE] => 1
    [dsParamREDIRECTONEMPTY] => no
    [dsParamSORT] => system:id
    [dsParamASSOCIATEDENTRYCOUNTS] => no
    [dsParamINCLUDEDELEMENTS] => Array
        (
            [0] => festivaljahr
            [1] => anfang
            [2] => ende
        )

    [dsParamSOURCE] => 2
    [_env:protected] => Array
        (
        )

    [_param_output_only:protected] => 
    [_dependencies:protected] => Array
        (
        )

    [_force_empty_result:protected] => 
    [_negate_result:protected] => 
    [dsParamFILTERS] => Array
        (
            [system:id] => 660, 624
        )

)

But the resulting XML tree looks like this:

XMLElement Object
(
    [_name:XMLElement:private] => associations
    [_value:XMLElement:private] => Array
        (
        )

    [_attributes:XMLElement:private] => Array
        (
        )

    [_children:XMLElement:private] => Array
        (
            [0] => XMLElement Object
                (
                    [_name:XMLElement:private] => section
                    [_value:XMLElement:private] => Aktuelles
                    [_attributes:XMLElement:private] => Array
                        (
                            [id] => 2
                            [handle] => aktuelles
                        )

                    [_children:XMLElement:private] => Array
                        (
                            [0] => Aktuelles
                        )

                    [_processingInstructions:XMLElement:private] => Array
                        (
                        )

                    [_dtd:XMLElement:private] => 
                    [_encoding:XMLElement:private] => utf-8
                    [_version:XMLElement:private] => 1.0
                    [_elementStyle:XMLElement:private] => xml
                    [_includeHeader:XMLElement:private] => 
                    [_selfclosing:XMLElement:private] => 1
                    [_allowEmptyAttributes:XMLElement:private] => 1
                )

            [1] => XMLElement Object
                (
                    [_name:XMLElement:private] => entry
                    [_value:XMLElement:private] => Array
                        (
                        )

                    [_attributes:XMLElement:private] => Array
                        (
                            [id] => 624
                        )

                    [_children:XMLElement:private] => Array
                        (
                        )

                    [_processingInstructions:XMLElement:private] => Array
                        (
                        )

                    [_dtd:XMLElement:private] => 
                    [_encoding:XMLElement:private] => utf-8
                    [_version:XMLElement:private] => 1.0
                    [_elementStyle:XMLElement:private] => xml
                    [_includeHeader:XMLElement:private] => 
                    [_selfclosing:XMLElement:private] => 1
                    [_allowEmptyAttributes:XMLElement:private] => 1
                )

            [2] => XMLElement Object
                (
                    [_name:XMLElement:private] => entry
                    [_value:XMLElement:private] => Array
                        (
                        )

                    [_attributes:XMLElement:private] => Array
                        (
                            [id] => 660
                        )

                    [_children:XMLElement:private] => Array
                        (
                        )

                    [_processingInstructions:XMLElement:private] => Array
                        (
                        )

                    [_dtd:XMLElement:private] => 
                    [_encoding:XMLElement:private] => utf-8
                    [_version:XMLElement:private] => 1.0
                    [_elementStyle:XMLElement:private] => xml
                    [_includeHeader:XMLElement:private] => 
                    [_selfclosing:XMLElement:private] => 1
                    [_allowEmptyAttributes:XMLElement:private] => 1
                )

        )

    [_processingInstructions:XMLElement:private] => Array
        (
        )

    [_dtd:XMLElement:private] => 
    [_encoding:XMLElement:private] => utf-8
    [_version:XMLElement:private] => 1.0
    [_elementStyle:XMLElement:private] => xml
    [_includeHeader:XMLElement:private] => 
    [_selfclosing:XMLElement:private] => 1
    [_allowEmptyAttributes:XMLElement:private] => 1
)

It's outputting the correct entries, only the fields are missing. Ideas?

nilshoerrmann commented 10 years ago

Doh! I seem to have stored the wrong field ids …