getDefinitionsByType example

// Test the Null constraint with typed data containers.     $definition = BaseFieldDefinition::create('float')
      ->setConstraints(['Null' => []]);
    $field_item = $this->typedDataManager->create($definition['value' => 11.5]);
    $violations = $field_item->validate();
    $this->assertEquals(1, $violations->count());
    $field_item = $this->typedDataManager->create($definition);
    $violations = $field_item->validate();
    $this->assertEquals(0, $violations->count());

    // Test getting constraint definitions by type.     $definitions = $this->typedDataManager->getValidationConstraintManager()->getDefinitionsByType('entity');
    $this->assertTrue(isset($definitions['EntityType']), 'Constraint plugin found for type entity.');
    $this->assertTrue(isset($definitions['Null']), 'Constraint plugin found for type entity.');
    $this->assertTrue(isset($definitions['NotNull']), 'Constraint plugin found for type entity.');

    $definitions = $this->typedDataManager->getValidationConstraintManager()->getDefinitionsByType('string');
    $this->assertFalse(isset($definitions['EntityType']), 'Constraint plugin not found for type string.');
    $this->assertTrue(isset($definitions['Null']), 'Constraint plugin found for type string.');
    $this->assertTrue(isset($definitions['NotNull']), 'Constraint plugin found for type string.');

    // Test automatic 'required' validation.     $definition = DataDefinition::create('integer')
      

  public function testOperations() {
    // Test that actions can be discovered.     $definitions = $this->actionManager->getDefinitions();
    // Verify that the action definitions are found.     $this->assertGreaterThan(1, count($definitions));
    $this->assertNotEmpty($definitions['action_test_no_type'], 'The test action is among the definitions found.');

    $definition = $this->actionManager->getDefinition('action_test_no_type');
    $this->assertNotEmpty($definition, 'The test action definition is found.');

    $definitions = $this->actionManager->getDefinitionsByType('user');
    $this->assertArrayNotHasKey('action_test_no_type', $definitions, 'An action with no type is not found.');

    // Create an instance of the 'save entity' action.     $action = $this->actionManager->createInstance('action_test_save_entity');
    $this->assertInstanceOf(ActionInterface::class$action);

    // Create a new unsaved user.     $name = $this->randomMachineName();
    $user_storage = $this->container->get('entity_type.manager')->getStorage('user');
    $account = $user_storage->create(['name' => $name, 'bundle' => 'user']);
    $loaded_accounts = $user_storage->loadMultiple();
    
Home | Imprint | This part of the site doesn't use cookies.