Skip to content
Snippets Groups Projects
Commit 52cbda8c authored by Rohit Rawat's avatar Rohit Rawat Committed by howard ge
Browse files

Issue #3002515 by RohitRawat676: Coding standards

parent f98761c3
Branches
No related tags found
No related merge requests found
Showing
with 71 additions and 74 deletions
......@@ -22,8 +22,7 @@ function field_validation_entity_bundle_field_info_alter(&$fields, EntityTypeInt
// 'ruleset_name' => $ruleset_name,
// 'rule_uuid' => '',
// ]);
//}
// }.
$rules = $ruleset->getFieldValidationRules();
foreach ($rules as $field_validation_rule) {
$field_name = $field_validation_rule->getFieldName();
......
......@@ -5,9 +5,9 @@ namespace Drupal\field_validation\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityWithPluginCollectionInterface;
use Drupal\field_validation\FieldValidationRuleSetInterface;
use Drupal\field_validation\FieldValidationRuleInterface;
use Drupal\field_validation\FieldValidationRulePluginCollection;
use Drupal\field_validation\FieldValidationRuleSetInterface;
/**
* Defines a field validation rule set configuration entity.
......
......@@ -2,12 +2,11 @@
namespace Drupal\field_validation;
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\PluginBase;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\field\Entity\FieldStorageConfig;
use \Drupal\Core\Utility\Token;
use Drupal\Core\Utility\Token;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -380,7 +379,6 @@ abstract class FieldValidationRuleBase extends PluginBase implements FieldValida
}
$value = $condition['value'] ?? "";
$entity_type = $entity->getEntityTypeId();
// Some entity not use entity_type_id as token type, we need change it.
switch ($entity_type) {
......@@ -404,38 +402,45 @@ abstract class FieldValidationRuleBase extends PluginBase implements FieldValida
$field_value = $entity->{$field_name}->{$main_property} ?? NULL;
// \Drupal::messenger()->addMessage("field_value:" .var_export($field_value,true));
// Type convert, do we need this code?
// if (is_int($field_value)) {
// $value = (int) $value;
// }elseif (is_float($field_value)) {
// $value = (float) $value;
// }
// \Drupal::messenger()->addMessage("value:" .var_export($value,true));
// \Drupal::messenger()->addMessage("value:" .var_export($value,true));.
switch ($operator) {
case 'equals':
return $field_value == $value;
break;
case 'not_equals':
return $field_value != $value;
break;
case 'greater_than':
return $field_value > $value;
break;
case 'less_than':
return $field_value < $value;
break;
case 'greater_or_equal':
return $field_value >= $value;
break;
case 'less_or_equal':
return $field_value <= $value;
break;
case 'empty':
return empty($field_value);
break;
case 'not_empty':
return !empty($field_value);
break;
}
......@@ -456,15 +461,13 @@ abstract class FieldValidationRuleBase extends PluginBase implements FieldValida
$entity = $items->getEntity();
$entity_type = $entity->getEntityTypeId();
// $entity_type = $entity->getEntityType()->label();
// Get bundle, do we need human name?
$bundle = $entity->bundle();
// $entity_type_id = $entity->getEntityTypeId();
// $bundle_id = $entity->bundle();
// $bundle_info = \Drupal::service('entity_type.bundle.info')->getBundleInfo($entity_type_id);
// $bundle = $bundle_info[$bundle_id]['label'];
// Get field name
// Get field name.
$field_name = $items->getFieldDefinition()->getLabel();
$value = $params['value'] ?? "";
......
......@@ -2,13 +2,13 @@
namespace Drupal\field_validation\Form;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\CachedDiscoveryClearerInterface;
use Drupal\field_validation\FieldValidationRuleManager;
use Drupal\field_validation\FieldValidationRuleSetInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Plugin\CachedDiscoveryClearerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
/**
* Provides an add form for field validation rule.
......
......@@ -2,18 +2,18 @@
namespace Drupal\field_validation\Form;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormState;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\CachedDiscoveryClearerInterface;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field_validation\ConfigurableFieldValidationRuleInterface;
use Drupal\field_validation\FieldValidationRuleSetInterface;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Plugin\CachedDiscoveryClearerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Provides a base form for FieldValidationRule.
......
......@@ -2,7 +2,6 @@
namespace Drupal\field_validation\Plugin\FieldValidationRule;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\field_validation\ConfigurableFieldValidationRuleBase;
use Drupal\field_validation\FieldValidationRuleSetInterface;
......
......@@ -21,7 +21,6 @@ class ItemCountFieldValidationRule extends ConfigurableFieldValidationRuleBase {
/**
* {@inheritdoc}
*/
public function addFieldValidationRule(FieldValidationRuleSetInterface $field_validation_rule_set) {
return TRUE;
}
......@@ -84,8 +83,8 @@ class ItemCountFieldValidationRule extends ConfigurableFieldValidationRuleBase {
* {@inheritdoc}
*/
public function validate($params) {
$rule = isset($params['rule']) ? $params['rule'] : NULL;
$context = isset($params['context']) ? $params['context'] : NULL;
$rule = $params['rule'] ?? NULL;
$context = $params['context'] ?? NULL;
$settings = [];
if (!empty($rule) && !empty($rule->configuration)) {
......
......@@ -2,8 +2,8 @@
namespace Drupal\field_validation\Plugin\FieldValidationRule;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Form\FormStateInterface;
use Drupal\field_validation\ConfigurableFieldValidationRuleBase;
use Drupal\field_validation\FieldValidationRuleSetInterface;
......
......@@ -4,8 +4,8 @@ namespace Drupal\Tests\field_validation\Kernel\Plugin\FieldValidationRule;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\node\Entity\NodeType;
use Drupal\field_validation\Plugin\Validation\Constraint\FieldValidationConstraint;
use Drupal\node\Entity\NodeType;
/**
* Tests ItemCountFieldValidationRule.
......
......@@ -2,9 +2,8 @@
namespace Drupal\Tests\field_validation\Kernel\Plugin\FieldValidationRule;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\node\Entity\NodeType;
/**
* Tests MatchFieldFieldValidationRule.
*
......@@ -84,7 +83,7 @@ class MatchFieldFieldValidationRuleTest extends FieldValidationRuleBase {
'entity_type' => "node",
'bundle' => "person",
'field_name' => "title",
]
],
]);
$this->ruleSet->save();
......@@ -104,7 +103,6 @@ class MatchFieldFieldValidationRuleTest extends FieldValidationRuleBase {
}
/**
*
* Tests MatchFieldFieldValidationRule.
*/
public function testMatchFieldRule() {
......@@ -121,4 +119,5 @@ class MatchFieldFieldValidationRuleTest extends FieldValidationRuleBase {
'Name1'
);
}
}
......@@ -2,8 +2,6 @@
namespace Drupal\Tests\field_validation\Kernel\Plugin\FieldValidationRule;
use Drupal\Core\Url;
/**
* Tests UrlFieldValidationRule.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment