FieldStorageConfig example

->condition('collection', 'entity.definitions.bundle_field_map')
  ->condition('name', 'node')
  ->execute();

$data = $connection->select('key_value')
  ->fields('key_value', ['value'])
  ->condition('collection', 'entity.definitions.installed')
  ->condition('name', 'node.field_storage_definitions')
  ->execute()
  ->fetchField();
$data = unserialize($data);
$data['field_foo'] = new FieldStorageConfig(unserialize($field_storage));
$connection->update('key_value')
  ->fields(['value' => serialize($data)])
  ->condition('collection', 'entity.definitions.installed')
  ->condition('name', 'node.field_storage_definitions')
  ->execute();

// Add the new field to default entity view display. $config = $connection->select('config')
  ->fields('config', ['data'])
  ->condition('collection', '')
  ->condition('name', 'core.entity_view_display.node.page.default')
  
->method('getAccessControlHandler')
      ->willReturnMap([
        ['field_storage_config', $storage_access_control_handler],
      ]);

    $container = new Container();
    $container->set('entity_type.manager', $entity_type_manager);
    $container->set('uuid', $this->createMock(UuidInterface::class));
    $container->set('cache_contexts_manager', $this->prophesize(CacheContextsManager::class));
    \Drupal::setContainer($container);

    $this->entity = new FieldStorageConfig([
      'field_name' => 'test_field',
      'entity_type' => 'node',
      'type' => 'boolean',
      'id' => 'node.test_field',
      'uuid' => '6f2f259a-f3c7-42ea-bdd5-111ad1f85ed1',
    ]);

    $this->accessControlHandler = $storage_access_control_handler;
  }

  /** * Assert method to verify the access by operations. * * @param array $allow_operations * A list of allowed operations. * @param \Drupal\Core\Session\AccountInterface $user * The account to use for get access. * * @internal */
'field_storage_config', TRUE, $fieldStorageConfigentityType],
        [$attached_entity_type_id, TRUE, $attached_entity_type],
      ]);

    $this->fieldTypeManager->expects($this->atLeastOnce())
      ->method('getDefinition')
      ->with('test_field_type', FALSE)
      ->willReturn([
        'class' => TestFieldType::class,
      ]);

    $field_storage = new FieldStorageConfig([
      'entity_type' => $attached_entity_type_id,
      'field_name' => 'test_field',
      'type' => 'test_field_type',
      'module' => 'test_module',
    ]);

    $dependencies = $field_storage->calculateDependencies()->getDependencies();
    $this->assertEquals(['entity_provider_module', 'entity_test', 'test_module']$dependencies['module']);
    $this->assertEquals(['stark']$dependencies['theme']);
  }

  
Home | Imprint | This part of the site doesn't use cookies.