Skip to content
This repository has been archived by the owner on Dec 8, 2020. It is now read-only.

Commit

Permalink
Merge pull request #23 from IUCN-ELC/develop
Browse files Browse the repository at this point in the history
New field: source_website_url
  • Loading branch information
melish authored Nov 14, 2018
2 parents d70f963 + 8a6296e commit fa933bf
Show file tree
Hide file tree
Showing 11 changed files with 281 additions and 49 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ dependencies:
- field.field.node.court_decision.field_related_website
- field.field.node.court_decision.field_seat_of_court
- field.field.node.court_decision.field_source
- field.field.node.court_decision.field_source_website
- field.field.node.court_decision.field_species
- field.field.node.court_decision.field_subdivision
- field.field.node.court_decision.field_territorial_subdivisions
Expand All @@ -65,6 +66,7 @@ dependencies:
- link
- text
- user
- wildlex_structure
id: node.court_decision.default
targetEntityType: node
bundle: court_decision
Expand Down Expand Up @@ -318,9 +320,10 @@ content:
weight: 35
label: above
settings:
link: false
link_field: field_source_website
target: _blank
third_party_settings: { }
type: entity_reference_label
type: label_as_link_formatter
region: content
field_species:
weight: 14
Expand Down Expand Up @@ -381,6 +384,7 @@ hidden:
field_official_publication: true
field_original_id: true
field_original_title: true
field_source_website: true
field_subdivision: true
field_url: true
field_wildlife_legislation: true
Expand Down
1 change: 1 addition & 0 deletions config/default/core.extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ module:
user: 0
views_ui: 0
wildlex_map: 0
wildlex_structure: 0
menu_link_content: 1
pathauto: 1
xmlsitemap: 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
uuid: 7c7f4915-6f5a-41e2-aba1-cdb607d355d9
langcode: en
status: true
dependencies:
config:
- field.storage.node.field_source_website
- node.type.court_decision
module:
- link
id: node.court_decision.field_source_website
field_name: field_source_website
entity_type: node
bundle: court_decision
label: 'Source Website'
description: ''
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings:
link_type: 17
title: 0
field_type: link
19 changes: 19 additions & 0 deletions config/default/field.storage.node.field_source_website.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
uuid: 187cf192-0b94-4cc0-ae98-a83caeb96808
langcode: en
status: true
dependencies:
module:
- link
- node
id: node.field_source_website
field_name: field_source_website
entity_type: node
type: link
settings: { }
module: link
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ dependencies:
module:
- elis_consumer
- node
_core:
default_config_hash: WtlDxNC8CWujIXrQHLxTOROKGl7fQVZsoR6OcoIGWyc
id: elis_consumer_court_decisions
class: null
field_plugin_method: null
Expand Down Expand Up @@ -110,6 +108,7 @@ process:
field_source:
source: source
plugin: taxonomy_term
field_source_website: sourceWebsite
field_appealed:
source: wildlifeAppealed
plugin: boolean
Expand Down
2 changes: 1 addition & 1 deletion robo
Submodule robo updated from a5d785 to d52a45
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ process:
field_source:
source: source
plugin: taxonomy_term
field_source_website: sourceWebsite
field_appealed:
source: wildlifeAppealed
plugin: boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public function fields() {
'referenceToNationalLegislationNotes' => 'Cited legislations',
'courtCase' => 'Type of case',
'source' => 'Source',
'sourceWebsite' => 'Source Website',
'wildlifeChargeSheet' => 'Charge Sheet'
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<?php

namespace Drupal\wildlex_structure\Plugin\Field\FieldFormatter;

use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Exception\UndefinedLinkTemplateException;
use Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase;
use Drupal\Core\Url;

use Drupal\Component\Utility\Unicode;
use Drupal\Core\Field\FieldDefinitionInterface;



use Drupal\Core\Path\PathValidatorInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;

use Drupal\link\LinkItemInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;



/**
* Plugin implementation of the 'label_as_link_formatter' formatter.
*
* @FieldFormatter(
* id = "label_as_link_formatter",
* label = @Translation("Label as link"),
* field_types = {
* "entity_reference"
* }
* )
*/
class labelAsLinkFormatter extends EntityReferenceFormatterBase {
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
return [
'link_field' => '',
'target' => '',
] + parent::defaultSettings();
}

/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$elements['link_field'] = [
'#title' => t('Get the link from another link field.'),
'#type' => 'textfield',
'#description' => 'machine name associated with the link type field',
'#default_value' => $this->getSetting('link_field'),
];
$elements['target'] = [
'#type' => 'checkbox',
'#title' => t('Open link in new window'),
'#return_value' => '_blank',
'#default_value' => $this->getSetting('target'),
];

return $elements;
}

/**
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = [];
$summary[] = $this->getSetting('link_field') ? t('Link from <em>@field</em>', ['@field' => $this->getSetting('link_field')]) : t('No link');
return $summary;
}

/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
$uri = FALSE;
$link_field = $this->getSetting('link_field');

/* @var \Drupal\node\Entity\Node $node */
$node = $items->getEntity();
if ($node && $node->{$link_field}) {
if ($node->{$link_field}->getFieldDefinition()->getType() == 'link') {
foreach ($node->{$link_field} as $delta => $item) {
// By default use the full URL as the link text.
$uri = $this->buildUrl($item);
}
}
}
if ($this->getEntitiesToView($items, $langcode)) {
foreach ($this->getEntitiesToView($items, $langcode) as $delta => $entity) {
$label = $entity->label();
if ($uri && !$entity->isNew()) {
$elements[$delta] = [
'#type' => 'link',
'#title' => $label,
'#url' => $uri,
'#options' => $uri->getOptions(),
];

if (!empty($items[$delta]->_attributes)) {
$elements[$delta]['#options'] += ['attributes' => []];
$elements[$delta]['#options']['attributes'] += $items[$delta]->_attributes;
// Unset field item attributes since they have been included in the
// formatter output and shouldn't be rendered in the field template.
unset($items[$delta]->_attributes);
}
}
else {
$elements[$delta] = ['#plain_text' => $label];
}
$elements[$delta]['#cache']['tags'] = $entity->getCacheTags();
}
} else {
if ($uri) {
$elements[] = [
'#type' => 'link',
'#title' => $uri->toString(),
'#url' => $uri,
'#options' => $uri->getOptions(),
];

if (!empty($items[$delta]->_attributes)) {
$elements[$delta]['#options'] += ['attributes' => []];
$elements[$delta]['#options']['attributes'] += $items[$delta]->_attributes;
// Unset field item attributes since they have been included in the
// formatter output and shouldn't be rendered in the field template.
unset($items[$delta]->_attributes);
}
}
}



return $elements;
}

/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity) {
return $entity->access('view label', NULL, TRUE);
}

protected function buildUrl(LinkItemInterface $item) {
$url = $item->getUrl() ?: Url::fromRoute('<none>');

$settings = $this->getSettings();
$options = $item->options;
$options += $url->getOptions();

// Add optional 'rel' attribute to link options.
if (!empty($settings['rel'])) {
$options['attributes']['rel'] = $settings['rel'];
}
// Add optional 'target' attribute to link options.
if (!empty($settings['target'])) {
$options['attributes']['target'] = $settings['target'];
}
$url->setOptions($options);

return $url;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: 'wildlex_structure'
type: module
description: 'Wildlex misc functionalities.'
core: 8.x
package: 'Custom'

0 comments on commit fa933bf

Please sign in to comment.