Build attributes.pl

From EPrints Documentation
Jump to: navigation, search

EPrints 3 Reference: Directory Structure - Metadata Fields - Repository Configuration - XML Config Files - XML Export Format - EPrints data structure - Core API - Data Objects


Back to cfg.d

build_attributes.pl allows for manipulating attributes before elements are created This function is called from perl_lib/EPrints/XML.pm sub create_element if present in configuration.

The examples below will allow for attributes to be manipulated with the following structure:

  1. Look for the attribute value in config, i.e. $c
  2. Apply any changes to that specific value i.e. either replace or add to it.
  3. If there are multiple attribute values it will cycle through them and repeat the above.

Examples

  • A class addition, useful for adding framework css classes
push @{$c->{config_attrs}->{class}->{"ep_search_controls"}}, ({ class => "framework-class", _change_action => "replace" });
  • A change to the elements id attribute, useful for overwriting layered css
push @{$c->{config_attrs}->{id}->{"ep_id_for_elem"}}, ({ id => "new_id", _change_action => "replace" });
  • Adding a new data attribute, useful for adding in accessibility attributes
push @{$c->{config_attrs}->{id}->{"ep_id_for_elem"}}, ({ "data_info" => "data-info" });
  • Creating a classname based on user account type
push @{$c->{config_attrs}->{class}->{"ep_page_thing"}}, ({ class => sub {
    my $repo = shift @_;
    if ( defined $repo->current_user && $repo->current_user->is_staff )
    {
        return "staff-member-class";
    }
    else
    {
        return "non-staff-class";
    }
}, _change_action => "replace" });