2

Using Structure to manage a bunch of content and I'd love to show the value of a single custom field to the right of the title. It is just a number field to identify a piece of artwork. I imagine there may be a hook or something to grab onto within Structure and grab the value, but I was wondering if anyone had done this before and had any advice to offer?

I do know that I could go the route of Zenbu to show more customized information in a standard channel entries display, but I'd prefer to keep my client in the Structure world if possible.

Thanks!

1

You'll need an Extension that taps into the structure_index_view_data hook:

function activate_extension() {
    $hooks = array(
        "structure_index_view_data" => "customise_structure"
    );

    foreach ($hooks as $hook => $method) {
        $data = array(
            'class' => __CLASS__,
            'method' => $method,
            'hook' => $hook,
            'settings' => "",
            'priority' => 10,
            'version' => $this->version,
            'enabled' => 'y'
        );
        $this->EE->db->insert($this->EE->db->dbprefix . 'extensions', $data);
    }//###   End of foreach   ###
}//###   End of activate_extension function

Then in your customise_structure method:

function customise_structure($data) {
    if ($this->extensions->end_script === TRUE)
        return $data;
    if ($this->EE->extensions->last_call !== FALSE)
    $data = $this->EE->extensions->last_call;

    foreach($data["data"] as $tab_id => $content) {
        foreach($content as $eid => $page) {
            //Use $page['entry_id'] to get the entry ID
            //Use $page['title'] to append and customise the row display

            ...

        }//###   End of foreach   ###
    }//###   End of foreach   ###
    return $data;
}//###   End of customise_structure function

Using the entry_id you could run a query for each loop getting the custom field then appending it to $page["title"] with relevant spacing or span to indent or style further.

Be warned though, do a query per loop would be consuming, you'd be better to do an initial loop building the entry_id list, then build a single SQL getting just the single custom field you require for all the entries.

This should be enough to get you up and running on building your own extension.

|improve this answer|||||
  • Peter, huge thanks for taking the time to run through this. I really appreciate it. Thanks. – noahkuhn Aug 26 '13 at 19:51
0

You can use a normal channel tag to show any custom fields you want. If it's not data that is part of the current page URL, you'll need to specify the entry_id and use dynamic="no".

|improve this answer|||||
  • Travis - @noahkuhn wants to customise the Control Panel view of Structure, not frontend. I imagine an extension could be used to tap into structure_index_view_data hook...? – Peter Lewis Aug 26 '13 at 18:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.