Commit 8997b04f authored by mxh's avatar mxh
Browse files

Issue #3279664 by mxh: Ensure respect of maxlength on label pattern

parent 60840292
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\access_records\AccessRecordInterface;
use Drupal\access_records\AccessRecordTypeInterface;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Field\Plugin\Field\FieldType\BooleanItem;
@@ -243,8 +244,8 @@ class AccessRecord extends EditorialContentEntityBase implements AccessRecordInt
      $string = $this->generateFallbackStringRepresentation();
    }

    if (strlen($string) > 255) {
      $string = substr($string, 0, 252) . '...';
    if (mb_strlen($string) > 255) {
      $string = Unicode::truncate($string, 255, TRUE, TRUE, 20);
    }

    return $string;
@@ -274,7 +275,14 @@ class AccessRecord extends EditorialContentEntityBase implements AccessRecordInt
      }
    }
    if (!empty($label_pattern)) {
      $this->ar_label->value = \Drupal::token()->replace($label_pattern, ['access_record' => $this], ['langcode' => $this->language()->getId()]);
      $string = (string) \Drupal::token()->replace($label_pattern, ['access_record' => $this], [
        'langcode' => $this->language()->getId(),
        'clear' => TRUE,
      ]);
      if (mb_strlen($string) > 255) {
        $string = Unicode::truncate($string, 255, TRUE, TRUE, 20);
      }
      $this->ar_label->value = $string;
    }
  }