You are here

public function WebformContentCreatorEntity::checkMaxFieldSizeExceeded in Webform Content Creator 8

Same name and namespace in other branches
  1. 2.x src/Entity/WebformContentCreatorEntity.php \Drupal\webform_content_creator\Entity\WebformContentCreatorEntity::checkMaxFieldSizeExceeded()

Check if field maximum size is exceeded.

Parameters

array $fields: Content type fields.

string $k: Field machine name.

string $decValue: Decrypted value.

Return value

int 1 if maximum size is exceeded, otherwise return 0.

Overrides WebformContentCreatorInterface::checkMaxFieldSizeExceeded

1 call to WebformContentCreatorEntity::checkMaxFieldSizeExceeded()
WebformContentCreatorEntity::mapNodeField in src/Entity/WebformContentCreatorEntity.php
Use a single mapping to set a Node field value.

File

src/Entity/WebformContentCreatorEntity.php, line 600

Class

WebformContentCreatorEntity
Defines the Webform Content creator entity.

Namespace

Drupal\webform_content_creator\Entity

Code

public function checkMaxFieldSizeExceeded(array $fields, $k, $decValue = "") {
  if (!array_key_exists($k, $fields) || empty($fields[$k])) {
    return 0;
  }
  $fieldSettings = $fields[$k]
    ->getSettings();
  if (empty($fieldSettings) || !array_key_exists('max_length', $fieldSettings)) {
    return 0;
  }
  $maxLength = $fieldSettings['max_length'];
  if (empty($maxLength)) {
    return 0;
  }
  if ($maxLength < strlen($decValue)) {
    \Drupal::logger(WebformContentCreatorInterface::WEBFORM_CONTENT_CREATOR)
      ->notice($this
      ->t('Problem: Field max length exceeded (truncated).'));
    return $maxLength;
  }
  return strlen($decValue);
}