Skip to content

Commit

Permalink
Allow using badge on long text fields
Browse files Browse the repository at this point in the history
  • Loading branch information
joecorall committed Jul 18, 2024
1 parent fa3aa63 commit 3ca51c3
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Plugin/Field/FieldFormatter/RightsStatementBadge.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\Component\Utility\Xss;

/**
* Plugin implementation of the 'islandora_rights_statements' formatter.
Expand All @@ -15,7 +16,9 @@
* label = @Translation("Islandora Rights Statement Badge"),
* field_types = {
* "string",
* "text"
* "text",
* "text_long",
* "text_with_summary"
* }
* )
*/
Expand Down Expand Up @@ -98,14 +101,18 @@ public function getBadge($uri) : array {
$color = $this->getSetting('image_color');
$style = $this->getSetting('button_style');

$uri = strip_tags($uri);
$uri = trim($uri);

// Just print the text if this isn't a rights statement URI.
if (filter_var($uri, FILTER_VALIDATE_URL) === FALSE || strpos($uri, '/vocab/') === FALSE) {
return ['#markup' => $uri];
return ['#markup' => Xss::filter($uri)];
}

// Extract just the statement terms from the URI to use in image URL.
$terms = substr($uri, strpos($uri, "/vocab/") + 7);
$terms = substr($terms, 0, strlen($terms) - 5);

if ($style == 'icons') {
$style_filename = "Icon-Only.";
// In case an unavailable color is picked.
Expand Down

0 comments on commit 3ca51c3

Please sign in to comment.