node_title_validation.module in Node Title Validation 8
Same filename and directory in other branches
Node title validation module file.
File
node_title_validation.moduleView source
<?php
/**
* @file
* Node title validation module file.
*/
use Drupal\Core\Entity\EntityTypeInterface;
/**
* Implements hook_help().
*/
function node_title_validation_help($section) {
$output = '';
switch ($section) {
case 'admin/help#node_title_validation':
$output = '<p>' . t('This module helps to validate node title with min/max characters,blacklist special characters,significant words and unique node titles .') . '</p>';
$output .= '<p>' . t('Validate the node title By:') . '</p>';
$output .= '<ul>';
$output .= '<li>' . t('Special Character & blacklisted words.') . '</li>';
$output .= '<li>' . t('Length (optionally specify min and/or max length.)') . '</li>';
$output .= '<li>' . t('Unique node title (for specific content type.)') . '</li>';
$output .= '</ul>';
break;
}
return $output;
}
/**
* Function for adding constraint.
*
* @param array $fields
* The fields array.
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*/
function _node_title_validation_add_constraint(array &$fields, EntityTypeInterface $entity_type) {
if ($entity_type
->id() == 'node' && !empty($fields['title'])) {
$fields['title']
->addConstraint('NodeTitleValidate', []);
}
}
/**
* Implements hook_entity_base_field_info_alter().
*/
function node_title_validation_entity_base_field_info_alter(&$fields, EntityTypeInterface $entity_type) {
_node_title_validation_add_constraint($fields, $entity_type);
}
/**
* Implements hook_entity_bundle_field_info_alter().
*/
function node_title_validation_entity_bundle_field_info_alter(&$fields, EntityTypeInterface $entity_type) {
_node_title_validation_add_constraint($fields, $entity_type);
}
Functions
Name | Description |
---|---|
node_title_validation_entity_base_field_info_alter | Implements hook_entity_base_field_info_alter(). |
node_title_validation_entity_bundle_field_info_alter | Implements hook_entity_bundle_field_info_alter(). |
node_title_validation_help | Implements hook_help(). |
_node_title_validation_add_constraint | Function for adding constraint. |