0

I tried to create a similar question before but it was unclear, hopefully I can narrow it a little bit:

So I'd like to create an authors-article webpage, such as: http://www.bmj.com/content/350/bmj.h2747 As you can see workplaces (affiliations) are displayed as footnotes in a separate block, after the list of authors.

I'm working on reproducing something similar with views. I have two content types (article and author) and authors are connected to articles with a node reference field. All the necessary data have been queried with a view and I'd like to alter $view->result with the help of a views_pre_render() hook:

function mymodule_views_pre_render (&$view) {

    if ($view->name == 'publi_author_views' && $view->current_display == 'panel_pane_1') {

        $workplaces = array();
        $workplaces_clean = array();
        $workplace_display = "";
        $workplace_count = "1";
        $author_display = "";

        foreach($view->result as $authors) {
            $workplace = $authors->field_field_publi_workplace[0]['rendered']['#markup'];
            $workplaces[] = $workplace;
        }

        unset($authors);
        unset($workplace);

        $workplaces_clean = array_unique($workplaces);

        foreach($workplaces_clean as $wp_clean) {
            foreach($view->result as $authors) {
                $author = $authors->node_title;
                $workplace = $authors->field_field_publi_workplace[0]['rendered']['#markup'];

                if ($wp_clean == $workplace) {
                    $authors->node_title = $author." <sup>".$workplace_count."</sup>";

                    $authors->field_field_fake_title[0]['rendered'] = array(
                        '#markup' => $author." <sup>".$workplace_count."</sup>",
                        '#access' => TRUE,
                    );
                }

            }

            $workplace_display .= "<sup>".$workplace_count."</sup> ".$wp_clean;
            $workplace_count = $workplace_count+1;
        }
    }
   }

I have two problems:

  1. How can I add to authors the number in superscript? As you can see in the code above I appended it to $authors->node_title, but it doesn't display HTML-entities. Then I created a "fake" field (field_field_fake_title) but it hasn't been rendered.
  2. How can I add the list of workplaces to a separate block? I created the $workplace_display variable with the necessary HTML-code but I wasn't able to put it into $view->result since it doesn't really belong to any of the rows.
3
  • You can use Global :PHP field and configure "Output code" using $row value like $row->title
    – latikas
    Commented Jul 1, 2015 at 13:35
  • This is an example where just using Views and one-direction relationships gets painful. Considering using the Relation module, or using a computed field on the article to store other items of interest about the article. Either approach would help you do to less logic in your Views.
    – tenken
    Commented Jul 1, 2015 at 14:56
  • After all I used views_post_render(&$view, &$output, &$cache) here: I did the necessary manipulations with the data of $view then rebuilt the $output inserting the new result into it.
    – StG
    Commented Jul 12, 2015 at 13:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.