[EP-tech] Render_value help
Adam Field
adam at adamfield.net
Wed Oct 25 09:29:05 BST 2017
Hi Jean-Marie
Try something like this (note that this is just typed into the email, so will have lots of errors).
--
Adam
#this is the render_value function that’s set in the field config
$c->{render_authors_with_images} = sub
{
my ($repo, $field, $value, $allangs, $nolink, $eprint) = @_;
my $frag = $repo->xml->create_document_fragment;
foreach my $person (@{$value})
{
$frag->appendChild($repo->call(‘render_author_as_link’, $repo, $person));
}
return $frag;
};
$c->{render_author_as_link} = sub
{
my ($repo, $author) = @_;
$name = EPrints::Utils::make_name_string($author->{name});
my $url = $repo->call(‘staff_link_url’, $name->{ppn});
my $image_url = $repo->call(‘staff_image_url’, $name->{ppn});
my $frag = $repo->xml->create_document_fragment;
my $a = $repo->xml->create_element(‘a’, href => $url);
$a->appendChild($repo->xml->create_text_node($name));
$frag->appendChild($a);
my $img = $repo->xml->create_element(‘img’, src => $image_url);
$frag->appendChild($img);
return $frag;
};
$c->{staff_link_url} = sub
{
my ($ppn) = @_;
return ‘http://myorganisation.org/staff/’ . $ppn; #build as required
};
$c->{staff_image_url} = sub
{
my ($ppn) = @_;
return ‘http://myorganisation.org/staff/images/’ . $ppn . ‘/profile_thumbnail.jpg’;
}
From: <eprints-tech-bounces at ecs.soton.ac.uk> on behalf of <Jean-Marie.Lebechec at inp-toulouse.fr>
Reply-To: <eprints-tech at ecs.soton.ac.uk>
Date: Wednesday, 25 October 2017 09:04
To: <eprints-tech at ecs.soton.ac.uk>
Subject: Re: [EP-tech] Render_value help
Hi again Adam,
How to add a hyperlink and especially an image associated with this link? Which method to use?
Thank you.
Jean-Marie
Le 25/10/2017 à 08:17, Jean-Marie.Lebechec at inp-toulouse.fr a écrit :
Ah yes, thank you. I understood better the mechanism ! It is sometimes (often) difficult to debug Eprints :-)
Jean-Marie
Le 24/10/2017 à 16:23, Adam Field a écrit :
You need to return a dom object from a render function. Here are a couple of replacement lines:
….
push @authors, EPrints::Utils::make_name_string( $_->{name} );
…
return $repo->xml->create_text_node(join(‘; ‘, @authors));
Move the return to the bottom of the function, aswell. At the moment it’s in the loop. Also, I think your render_value config line may belong outside the fields section.
--
Adam
From: <eprints-tech-bounces at ecs.soton.ac.uk> on behalf of <Jean-Marie.Lebechec at inp-toulouse.fr>
Reply-To: <eprints-tech at ecs.soton.ac.uk>
Date: Tuesday, 24 October 2017 15:07
To: <eprints-tech at ecs.soton.ac.uk>
Subject: [EP-tech] Render_value help
Hi all,
I want to modify the rendering field creators to add an ID ("ppn") as indicated in this page. So I defined in my eprint_field.pl this configuration:
{
'name' => 'creators',
'type' => 'compound',
'allow_null' => 1,
'multiple' => 1,
'fields' => [
{
'sub_name' => 'ppn',
'type' => 'text',
'input_cols' => 10,
'allow_null' => 1,
},
{
'sub_name' => 'name',
'type' => 'name',
'hide_honourific' => 1,
'hide_lineage' => 1,
'family_first' => 1,
},
},
{
'sub_name' => 'id',
'type' => 'text',
'input_cols' => 20,
'allow_null' => 1,
},
],
'input_boxes' => 4,
'render_value' => 'idref',
...
}
but I can not write the code to display the authors' data in the following form:
"Name, First name (ppn) and Name, First name and Name, First name (ppn)" for example.
I started writing things like this:
$c->{idref} = sub
{
my ($repo, $field, $value, $allangs, $nolink, $eprint) = @_;
my @authors;
for( @{ $eprint->value( "creators" ) } )
{
push @authors, {
author => EPrints::Utils::make_name_string( $_->{name} ),
};
return \@authors;
}
}
but it does not work....
Any help or example will be welcome!
Jean-Marie
--
***********************************************
Jean Marie Le Bechec
Service Commun de la Documentation
Responsable ingenierie documentaire
&
Direction du Systeme d'Information
Referent Etudes
Institut National Polytechnique de Toulouse
6 allee Emile Monso - bp 34038 -
31029 Toulouse cedex 4
Tel : 05 34 32 31 16
Tel Port : 06 40 81 35 68
Mail : lebechec at inp-toulouse.fr
***********************************************
*** Options: http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech *** Archive: http://www.eprints.org/tech.php/ *** EPrints community wiki: http://wiki.eprints.org/ *** EPrints developers Forum: http://forum.eprints.org/
*** Options: http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech
*** Archive: http://www.eprints.org/tech.php/
*** EPrints community wiki: http://wiki.eprints.org/
*** EPrints developers Forum: http://forum.eprints.org/
--
***********************************************
Jean Marie Le Bechec
Service Commun de la Documentation
Responsable ingenierie documentaire
&
Direction du Systeme d'Information
Referent Etudes
Institut National Polytechnique de Toulouse
6 allee Emile Monso - bp 34038 -
31029 Toulouse cedex 4
Tel : 05 34 32 31 16
Tel Port : 06 40 81 35 68
Mail : lebechec at inp-toulouse.fr
***********************************************
*** Options: http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech
*** Archive: http://www.eprints.org/tech.php/
*** EPrints community wiki: http://wiki.eprints.org/
*** EPrints developers Forum: http://forum.eprints.org/
--
***********************************************
Jean Marie Le Bechec
Service Commun de la Documentation
Responsable ingenierie documentaire
&
Direction du Systeme d'Information
Referent Etudes
Institut National Polytechnique de Toulouse
6 allee Emile Monso - bp 34038 -
31029 Toulouse cedex 4
Tel : 05 34 32 31 16
Tel Port : 06 40 81 35 68
Mail : lebechec at inp-toulouse.fr
***********************************************
*** Options: http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech *** Archive: http://www.eprints.org/tech.php/ *** EPrints community wiki: http://wiki.eprints.org/ *** EPrints developers Forum: http://forum.eprints.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ecs.soton.ac.uk/pipermail/eprints-tech/attachments/20171025/c049a916/attachment-0001.html
More information about the Eprints-tech
mailing list