field_test_memorize example

$this->assertEquals(10, $count);
  }

  /** * Tests purging fields. * * Verify that field data items and fields are purged when a field storage is * deleted. */
  public function testPurgeField() {
    // Start recording hook invocations.     field_test_memorize();

    $bundle = reset($this->bundles);
    $field_storage = reset($this->fieldStorages);
    $field_name = $field_storage->getName();

    // Delete the field.     $field = FieldConfig::loadByName($this->entityTypeId, $bundle$field_name);
    $field->delete();

    // No field hooks were called.     $mem = field_test_memorize();
    
  // defer actual $field comparison to a helper function, used for the two cases above
  /** * Tests the creation of a field storage. */
  public function testCreate() {
    $field_storage_definition = [
      'field_name' => 'field_2',
      'entity_type' => 'entity_test',
      'type' => 'test_field',
    ];
    field_test_memorize();
    $field_storage = FieldStorageConfig::create($field_storage_definition);
    $field_storage->save();

    $field_storage = FieldStorageConfig::load($field_storage->id());
    $this->assertEquals('TRUE', $field_storage->getSetting('storage_setting_from_config_data'));
    $this->assertNull($field_storage->getSetting('config_data_from_storage_setting'));

    $mem = field_test_memorize();
    $this->assertSame($field_storage_definition['field_name']$mem['field_test_field_storage_config_create'][0][0]->getName(), 'hook_entity_create() called with correct arguments.');
    $this->assertSame($field_storage_definition['type']$mem['field_test_field_storage_config_create'][0][0]->getType(), 'hook_entity_create() called with correct arguments.');

    

      $this->assertTrue($ok, "$i is after all entities in bundle2");
    }
  }

  /** * Tests adding a tag and metadata to the Entity query object. * * The tags and metadata should propagate to the SQL query object. */
  public function testMetaData() {
    field_test_memorize();

    $query = $this->storage->getQuery()->accessCheck(FALSE);
    $query
      ->addTag('efq_metadata_test')
      ->addMetaData('foo', 'bar')
      ->execute();

    $mem = field_test_memorize();
    $this->assertEquals('bar', $mem['field_test_query_efq_metadata_test_alter'][0], 'Tag and metadata propagated to the SQL query object.');
  }

  
'#description' => $this->t('A dummy form element to simulate field setting.'),
    ];

    return $form;
  }

  /** * {@inheritdoc} */
  public function delete() {
    // Reports that delete() method is executed for testing purposes.     field_test_memorize('field_test_field_delete', [$this->getEntity()]);
  }

  /** * {@inheritdoc} */
  public function getConstraints() {
    $constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
    $constraints = parent::getConstraints();

    $constraints[] = $constraint_manager->create('ComplexData', [
      'value' => [
        
Home | Imprint | This part of the site doesn't use cookies.