Create a sister module Node Body Validator

Created on 8 January 2021, almost 4 years ago
Updated 20 September 2023, over 1 year ago

Problem/Motivation

I needed a Node Body Validator

Steps to reproduce

I cloned Node Title Validation

1.changed all occurrences from title to body (almost all)
2. changed

        //if (mb_strlen($value_body) < $config_value) {
        if (_rip_tags($value_body) < $config_value) {

and

        //if (mb_strlen($value_body) > $config_value) {
        if (_rip_tags($value_body) > $config_value) {

added _rip_tags function at the end of NodeBodyConstraintValidator.php

3. changes in NodeTitleValidationAdminForm.php

       $form[$type->get('type')]['min-' . $type->get('type')] = [
        '#type' => 'number',
        '#title' => $this->t("Minimum characters"),
        '#required' => TRUE,
        '#description' => $this->t("Minimum number of characters node body should contain"),
        '#max' => 9999,
        '#min' => 1,
        '#default_value' => isset($node_body_validation_config['min-' . $type->get('type')]) ? $node_body_validation_config['min-' . $type->get('type')] : 1,
      ];

      $form[$type->get('type')]['max-' . $type->get('type')] = [
        '#type' => 'number',
        '#title' => $this->t("Maximum characters"),
        '#required' => TRUE,
        '#description' => $this->t("Maximum number of characters node body should contain"),
        '#max' => 9999,
        '#min' => 1,
        '#default_value' => isset($node_body_validation_config['max-' . $type->get('type')]) ? $node_body_validation_config['max-' . $type->get('type')] : 9999,
      ];

      $form[$type->get('type')]['min-wc-' . $type->get('type')] = [
        '#type' => 'number',
        '#title' => $this->t("Minimum Word Count"),
        '#required' => TRUE,
        '#description' => $this->t("Minimum number of words node body should contain"),
        '#max' => 4999,
        '#min' => 1,
        '#default_value' => isset($node_body_validation_config['min-wc-' . $type->get('type')]) ? $node_body_validation_config['min-wc-' . $type->get('type')] : 1,
      ];

      $form[$type->get('type')]['max-wc-' . $type->get('type')] = [
        '#type' => 'number',
        '#title' => $this->t("Maximum Word Count"),
        '#description' => $this->t("Maximum number of words node body should contain"),
        '#max' => 4999,
        '#min' => 1,
        '#default_value' => isset($node_body_validation_config['max-wc-' . $type->get('type')]) ? $node_body_validation_config['max-wc-' . $type->get('type')] : 4999,
      ];

Proposed resolution

Maybe you guys want to make a sister module : Node Body Validator.

Remaining tasks

Make the Node Body Validator module.

--
I hope this helps somebody.

Feature request
Status

Active

Version

1.22

Component

Miscellaneous

Created by

🇷🇴Romania idflorin

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
Production build 0.71.5 2024