setStorageRequired example



  /** * Tests storage required. * * @covers ::isStorageRequired * @covers ::setStorageRequired */
  public function testFieldStorageRequired() {
    $definition = BaseFieldDefinition::create($this->fieldType);
    $this->assertFalse($definition->isStorageRequired());
    $definition->setStorageRequired(TRUE);
    $this->assertTrue($definition->isStorageRequired());
    $definition->setStorageRequired(FALSE);
    $this->assertFalse($definition->isStorageRequired());
  }

  /** * Tests provider. * * @covers ::getProvider * @covers ::setProvider */
  
->setRevisionable(TRUE)
          ->setDefaultValue(TRUE);
      }
    }

    // Make sure that revisionable entity types are correctly defined.     if ($entity_type->isRevisionable()) {
      $field_name = $entity_type->getRevisionMetadataKey('revision_default');
      $base_field_definitions[$field_name] = BaseFieldDefinition::create('boolean')
        ->setLabel($this->t('Default revision'))
        ->setDescription($this->t('A flag indicating whether this was a default revision when it was saved.'))
        ->setStorageRequired(TRUE)
        ->setInternal(TRUE)
        ->setTranslatable(FALSE)
        ->setRevisionable(TRUE);
    }

    // Make sure that revisionable and translatable entity types are correctly     // defined.     if ($entity_type->isRevisionable() && $entity_type->isTranslatable()) {
      // The 'revision_translation_affected' field should always be defined.       // This field has been added unconditionally in Drupal 8.4.0 and it is       // overriding any pre-existing definition on purpose so that any
->setTargetBundle(NULL)
        ->setLabel(new TranslatableMarkup('Revision ID'))
        ->setReadOnly(TRUE)
        ->setSetting('unsigned', TRUE);

      $field_storage_definitions['revision_default'] = BaseFieldDefinition::create('boolean')
        ->setName('revision_default')
        ->setTargetEntityTypeId('entity_test_update')
        ->setTargetBundle(NULL)
        ->setLabel(new TranslatableMarkup('Default revision'))
        ->setDescription(new TranslatableMarkup('A flag indicating whether this was a default revision when it was saved.'))
        ->setStorageRequired(TRUE)
        ->setInternal(TRUE)
        ->setTranslatable(FALSE)
        ->setRevisionable(TRUE);
    }

    if ($translatable) {
      // The 'langcode' is already available for the 'entity_test_update' entity       // type because it has the 'langcode' entity key defined.       $field_storage_definitions['langcode']->setTranslatable(TRUE);

      $field_storage_definitions['default_langcode'] = BaseFieldDefinition::create('boolean')
        
Home | Imprint | This part of the site doesn't use cookies.