Skip to content

Commit

Permalink
Ensure no errors when no image.
Browse files Browse the repository at this point in the history
  • Loading branch information
laceysanderson committed Sep 27, 2019
1 parent 6992c39 commit 277bfb4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion includes/TripalFields/analyzedphenotypes.fields.inc
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function analyzedphenotypes_bundle_fields_info($entity_type, $bundle) {

// Phenotype Image
tripal_insert_cvterm(array(
'id' => 'ncit:c48179',
'id' => 'NCIT:C48179',
'name' => 'Image',
'cv_name' => 'NCIT',
'definition' => 'Phenotype Image.',
Expand Down
14 changes: 9 additions & 5 deletions includes/TripalFields/ncit__image/ncit__image.inc
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ class ncit__image extends ChadoField {
// required for all TripalFields.
public static $default_instance_settings = array(
// The short name for the vocabulary (e.g. schema, SO, GO, PATO, etc.).
'term_vocabulary' => 'ncit',
'term_vocabulary' => 'NCIT',
// The name of the term.
'term_name' => 'Image',
// The unique ID (i.e. accession) of the term.
'term_accession' => 'c48179',
'term_accession' => 'C48179',
// Set to TRUE if the site admin is not allowed to change the term
// type, otherwise the admin can change the term mapped to a field.
'term_fixed' => FALSE,
Expand Down Expand Up @@ -111,10 +111,14 @@ class ncit__image extends ChadoField {
*
*/
public function load($entity) {
$field_name = $this->instance['field_name'];

$trait_photo = ap_download_cvtermphoto($entity->chado_record_id);
if ($trait_photo) {
$field_name = $this->instance['field_name'];
$entity->{$field_name}['und'][0]['value']['ncit:c48179'] = $trait_photo;
if (is_array($trait_photo) AND !empty($trait_photo['ap_photo_1'])) {
$entity->{$field_name}['und'][0]['value']['NCIT:C48179'] = $trait_photo;
}
else {
$entity->{$field_name}['und'][0]['value'] = '';
}
}
}
10 changes: 7 additions & 3 deletions includes/TripalFields/ncit__image/ncit__image_formatter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,14 @@ class ncit__image_formatter extends TripalFieldFormatter {
* hook_field_formatter_view() function.
*/
public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
drupal_add_css(drupal_get_path('module', 'analyzedphenotypes') . '/includes/TripalFields/ncit__c48179/theme/style_phenotype_image.css');
drupal_add_js(drupal_get_path('module', 'analyzedphenotypes') . '/includes/TripalFields/ncit__c48179/theme/script.js');
drupal_add_css(drupal_get_path('module', 'analyzedphenotypes') . '/includes/TripalFields/ncit__image/theme/style_phenotype_image.css');
drupal_add_js(drupal_get_path('module', 'analyzedphenotypes') . '/includes/TripalFields/ncit__image/theme/script.js');

$trait_photo = array_values($items[0]['value']['ncit:c48179']);
// If there is no photo then don't render anything.
if (empty($items[0]['value'])) {
return '';
}
$trait_photo = array_values($items[0]['value']['NCIT:C48179']);

// Refer to this ID for CSS styling.
$id = 'ap-field-phenotype-image-wrapper';
Expand Down

0 comments on commit 277bfb4

Please sign in to comment.