Verified Commit f91e76e5 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3274419 by Marios Anagnostopoulos, Shubham Chandra, ravi.shankar, Alex...

Issue #3274419 by Marios Anagnostopoulos, Shubham Chandra, ravi.shankar, Alex Bukach, alexpott, smustgrave: Make BaseFieldOverride inherit internal property from the base field
parent 257191b8
Loading
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -148,6 +148,13 @@ public function isComputed() {
    return $this->getBaseFieldDefinition()->isComputed();
  }

  /**
   * {@inheritdoc}
   */
  public function isInternal(): bool {
    return $this->getBaseFieldDefinition()->isInternal();
  }

  /**
   * {@inheritdoc}
   */
+32 −0
Original line number Diff line number Diff line
@@ -82,6 +82,38 @@ public function testDefaultValueCallback() {
    $this->assertEquals([['target_id' => 99]], $base_field_override->getDefaultValue($entity));
  }

  /**
   * Tests that some properties are inherited from the BaseFieldDefinition.
   *
   * @covers ::isReadOnly
   * @covers ::isComputed
   * @covers ::isInternal
   * @covers ::getUniqueIdentifier
   */
  public function testInheritedProperties() {
    $base_field = BaseFieldDefinition::create('string')
      ->setName('Test Field')
      ->setTargetEntityTypeId('entity_test')
      ->setReadOnly(TRUE)
      /** Ensure that the internal property is inherited from the base field and not the parent class. @see FieldConfigBase::isInternal */
      ->setInternal(TRUE)
      ->setComputed(FALSE);

    // Getters of the properties to check.
    $methods = [
      'getUniqueIdentifier',
      'getClass',
      'isComputed',
      'isReadOnly',
      'isInternal',
    ];

    $override = BaseFieldOverride::createFromBaseFieldDefinition($base_field, 'test_bundle');
    foreach ($methods as $method) {
      $this->assertEquals($base_field->$method(), $override->$method());
    }
  }

  /**
   * A default value callback which returns a primitive value.
   *