Plugin Wordpress Coeli

Developer Documentation

Templating

To replace styles used by Coeli create a folder coeli/css/your-style-sheet.css at the root of your wordpress theme:

theme-name/coeli/css/record.css (replace record page stylesheet)
theme-name/coeli/css/search.css (replace search page stylesheet)

To replace templates used by Coeli create a folder coeli/template-to-overwrite.php at the root of your wordpress theme:

We have the following templates that can be rewritten:

theme-name/coeli/record.php

The templates must include the following mandatory inits:

<?php
coeli_init_record();
<?php
coeli_init_results($atts, "search");
<?php
coeli_init_results($atts, "list");

We can rewrite a determined endpoint indicating its identifier at the end of the file name. For example:

theme-name/coeli/record-actor.php

Inside the search and list templates we have the following objects:

<?php
//array that contains all the information of the search consulted in Coeli
coeli()->settings["current_search"];

Inside the record we have the following objects:

<?php
//array that contains all the information of the record consulted in Coeli
coeli()->record["data"];
<?php
//array that contains all the configuration of the record saved in the Wordpress administration: Selected fields, seo title field, seo desc field, img alt field
coeli()->record["conf"];
//Structure example array returned
Array
(
    [camps] => Array
        (
            [0] => Array
                (
                    [id] => departmentOrSection
                    [name] => Departament / Secció
                    [name_short] => Departament / Secció
                    [cerques] => 
                    [active] => 
                )

            [1] => Array
                (
                    [id] => collection
                    [name] => Col·lecció / Fons
                    [name_short] => Col·lecció / Fons
                    [cerques] => 
                    [active] => 
                )

            [2] => Array
                (
                    [id] => objectNumber
                    [name] => Número de l'objecte
                    [name_short] => Número de l'objecte
                    [cerques] => 
                    [active] => 1
                )
             ...   
    [title_seo] => 
    [desc_seo] => 
    [alt_img] => 

How to extract the slug and endpoint from the record page:

<?php
$slug = get_query_var('coeli_slug');
$endpoint = strtolower(get_query_var("coeli_endpoint"));

Create custom searches

Custom searches can be created using the following class:

<?php
/*example init search*/
$search = new COELI_Search( array(
		"endpoint"         => "HeritageObject",
		"limit"            => 20,
		"search_in_fields" => [ "collection", "classifications" ],
		"offset"           => 0,
		"lang"             => "ca",
		"skip_get_params"  => true,
		"default_order"    => [ "orderby" => "production.date", "order" => "DESC" ],
		"all_facets"       => true,
		"view_properties"  => ['display','objectNames'], 
		"facets"           => [ [ "collection", "name", "belongsTo" ], [ "classifications", "size", "equals", 5000 ] ],
		"query"            => [
			[ "field" => "departmentOrSection", "value" => "/coeli/FPC/DepartmentOrSection/FPC" ],
			[ "field" => "objectNames", "value" => "/coeli/FPC/SKOSConcept/254963" ],
			[ "field" => "materialsTechs.techniques", "value" => "/coeli/FPC/SKOSConcept/a torn, esmalt" ]
		]
	)
);
/* returns an object with the following structure:
  [entities] => Array
        (
            [0] => Array
                (
        ....all the entities matching the search

  [total] => 2884 // total number of entities
  [facets] => [] // array of facets if requested  
  [has_next_page] => true  // if the search have next page
  [offset] => 0
  [limit] => 20
  [originalSearch] => // the original search sent to coeli API   
)
*/

The parameter is an array with the following keys:

For searches between dates add condition as following:

<?php
[ "field" => "production.date", "value" => "1930|1970" ];

For searches with custom operator:

<?php
[ "field" => "classifications", "operator" => "equals", "value" => "/coeli/VINSEUM/SKOSConcept/110547" ];

Available operators: belongs_to, contains, contains_all, contains_any, exactly_contains, =, is_defined, >, <

For general text searches use:

<?php
[ "field" => "\$text", "value" => "text to find entire collection" ];
//if search_in_fields is set the searches are restricted to these fields

Functions

coeli_get_list_by_id(int $id_list_wp,int $offset = 0,int $limit = 15, array $extra_params = [])

Returns the list of items in array format

Parameters

coeli_get_group_by_id(int $id_agrupacio_wp)

Returns the list of entities in array format

Parameters

coeli_get_field_html(string $id = "",string $separator = " · ", bool $linkable = false, array $node)

Returns the value of a json field formatted in HTML

Parameters

coeli_get_field_raw(string $id,array $array_node) : array | string | undefined | null;

It may return an array if the property is a repeater, or the label final or undefined if the property is empty or does not exist

Parameters

<?php
$representations =  coeli_get_field_raw('representations',$coeli_entity_data);
if($representations){
    foreach ($representations as $r){
        if(coeli_get_field_raw("uri",$r)){
            echo '<img src="'.coeli_get_field_raw("uri.medium",$r).'">';
        }
    }
}

coeli_get_label(string $id,string $endpoint) : string;

Returns the label of a Coeli property or the one defined in Wordpress

Parameters

<?php
$label = coeli_get_label("accession.number","HeritageObject");
// $label = Accession number

Returns the url of a particular record. You must pass the endpoint, the slug of the entity and if we want to add a language.

Parameters

<?php
$link = coeli_get_link_record("HeritageObject","vinseum-11510--nc-gasteropode-conquilles");
// $link = https://examplesite.cat/heritageobject/vinseum-11510--nc-gasteropode-conquilles

Filters

coeli_get_miniature

It can be used to rewrite the html of the miniatures of the listings. Ex:

Parameters

<?php
function rewrite_miniature($html,$entity,$fields){
  return '<a href="">'.$entity["classifications"][0]["label"].'</a>';
}
add_filter( 'coeli_get_miniature', 'rewrite_miniature', 10, 3);

coeli_get_item_value

It is used to rewrite the way a certain field is presented in the record page (of those that have been selected in the admin). Ex:

Parameters

<?php
function rewrite_test($html,$id,$entity){
  if ($id == "webResources" && isset($entity["webResources"])) {
        $links = "";
        foreach ($entity["webResources"] as $w) {
            $links .= '<li><a target="_blank" href="' . $w["url"] . '">' . $w["title"] . '</a></li>';
        }
        return ($links != '')? '<ul>' . $links . '</ul>': '';
    } else {
        return $html;
    }
}
add_filter( 'coeli_get_item_value', 'rewrite_test', 10, 3);

coeli_render_embedded

It is used to rewrite the way an embedded field is presented in the record page (of those that have been selected in the admin). Ex:

Parameters

<?php 
function rewrite_appellations( $output, $id_embedded, $embedded_json, $endpoint ) {

	if ( $id_embedded !== "appellations" ) {
		return $output;
	}
	$embedded_output = "";
	if ( $embedded_json ) {
		$embedded_output .= '<li class="coeli-embedded ' . sanitize_title( $id_embedded ) . '" aria-label="' . coeli_get_label( $id_embedded,
				$endpoint, false ) . '">';
		$embedded_output .= '<h3>' . coeli_get_label( $id_embedded, $endpoint, false ) . '</h3>';
		$embedded_output .= '<table>
								<tr>
							    	<th>' . coeli_get_label( "appellations.display", $endpoint ) . '</th>
							    	<th>' . coeli_get_label( "appellations.text", $endpoint ) . '</th>
							  	</tr>';
		foreach ( $embedded_json as $item_row ) {
			$embedded_output .= '<tr>';
			$embedded_output .= '<td>' . coeli_get_item_value( "display", $item_row ) . '</td>';
			$embedded_output .= '<td>' . coeli_get_item_value( "text", $item_row ) . '</td>';
			$embedded_output .= '</tr>';
		}
		$embedded_output .= '</table></li>';

		return $embedded_output;
	}
}

add_filter( 'coeli_render_embedded', 'rewrite_appellations', 10, 4 );

coeli_get_no_representation_img

It is used to change the default image for records that do not have a representative one

<?php
function callback(){
    return 'img_url.jpg';
}
add_filter('coeli_get_no_representation_img','callback',10,0);

coeli_set_value_separator

It is used to change the default separator for properties with several values

<?php
function callback(){
    return ', ';
}
add_filter('coeli_set_value_separator','callback',10,0);

Parameters

<?php
function callback($html,$representations){
    $output = '<div class="representations-container">';
    foreach($representations as $r){
        //get representation info
        $img = coeli_get_field_raw('uri.small', $r);
        $output .= '<div class="image-row">';
        ...
    }
    $output .= '</div>';
    return $output;
}
add_filter('coeli_get_gallery','callback',10,2);

coeli_list_form_keyword_params

It is used to indicate if the keyword search form should keep the current filters or search all the collection. Default behavior is to keep the current filters.

<?php
function change_send_params(){
	return false;
}

add_filter( 'coeli_list_form_keyword_params', 'change_send_params' );

Actions

They have a parameter that is an array with all the fields of the record in Coeli

<?php
add_action("before_coeli_container_record","add_html",10,1);
function add_html($all_record_data){
   echo '<p>test action before the container of the record page</p>';
}

Other customizations

Change label 'show more' in list results

<?php
add_filter( 'gettext', 'coeli_change_see_more_results', 20, 3 );
function coeli_change_next_title_page( $translated_text, $text, $domain ) {
    if($text === 'Veure més' && $domain === "coeli") {
        $translated_text = __( 'Load more...', 'your_theme_text_domain' );
    }
    return $translated_text;
} 

Deployment

Pushing the develop or main branch will create the package and deploy the necessary files to the corresponding S3 bucket:

develop

main