HideLinkWhenTitleIsEmpty.php in Field Formatter Condition 8
File
src/Plugin/Field/FieldFormatter/Condition/HideLinkWhenTitleIsEmpty.php
View source
<?php
namespace Drupal\fico\Plugin\Field\FieldFormatter\Condition;
use Drupal\fico\Plugin\FieldFormatterConditionBase;
class HideLinkWhenTitleIsEmpty extends FieldFormatterConditionBase {
public function alterForm(&$form, $settings) {
}
public function access(&$build, $field, $settings) {
if (!empty($build[$field]['#items'])) {
foreach ($build[$field]['#items'] as $item) {
$info = $item
->getValue($field);
if (!$info['title'] || $info['title'] === $info['uri']) {
$build[$field]['#access'] = FALSE;
}
}
}
if (empty($build[$field]['#items'])) {
$build[$field]['#access'] = FALSE;
}
}
public function summary($settings) {
return t('Condition: %condition', [
"%condition" => t('Hide link when link title is empty'),
]);
}
}