createField example



  /** * Runs the field CRUD tests. * * In order to act on the same fields, and not create the fields over and over * again the following tests create, update and delete the same fields. */
  public function testCRUDFields() {
    $this->manageFieldsPage();
    $this->createField();
    $this->updateField();
    $this->addExistingField();
    $this->cardinalitySettings();
    $this->fieldListAdminPage();
    $this->deleteField();
    $this->addPersistentFieldStorage();
  }

  /** * Tests the manage fields page. * * @param string $type * (optional) The name of a content type. */
if (isset($fieldset['label'])) {
            $class->setLabel($fieldset['label']);
        }

        if (isset($fieldset['options'])) {
            $class->setOptions($fieldset['options']);
        }

        $fields = [];
        foreach ($fieldset['fields'] as $field) {
            $fields[] = $this->createField($field);
        }

        $class->setFields($fields);

        return $class;
    }

    public function createField(array $field): Field
    {
        $class = new Field();
        $class->setName($field['name']);
        

    public function createCheckboxField(array $options)
    {
        $options += [
            'xtype' => 'checkboxfield',
        ];

        return $this->createField($options);
    }

    /** * Creates a Ext.form.field.ComboBox element. * http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.form.field.ComboBox * * This field type supports the following parameters which can be set * as options array value: * - name * - fieldLabel * - allowBlank * - store * - displayField * - valueField * * options { * string $name Required; Logical name of the component field * string $displayField Required; Field name of the model which displays as text * string $valueField Required; Identifier field of the combo box * string $fieldLabel optional; Ext JS form field label * string $store optional; Store class which used for the combo class * string $allowBlank Optional; Defines if the value can contain null * } * * @param array{name: string, displayField: string, valueField: string, store?: string, fieldLabel?: string, allowBlank?: bool} $options * * @return Field */
'administer entity_test content',
      'administer entity_test form display',
      'administer content types',
      'bypass node access',
      'administer node fields',
      'administer node form display',
      'administer node display',
    ]);
    $this->drupalLogin($web_user);

    // Create a field with settings to validate.     $this->createField();

    $this->dateFormatter = $this->container->get('date.formatter');
  }

  /** * Creates a date test field. */
  protected function createField() {
    $field_name = mb_strtolower($this->randomMachineName());
    $field_label = Unicode::ucfirst(mb_strtolower($this->randomMachineName()));
    $type = $this->getTestFieldType();
    
'format' => 'no_filters',
      'name' => 'No filters',
      'filters' => [],
    ])->save();
  }

  /** * Tests processed properties. */
  public function testCrudAndUpdate() {
    $entity_type = 'entity_test';
    $this->createField($entity_type);

    // Create an entity with a summary and no text format.     $storage = $this->container->get('entity_type.manager')
      ->getStorage($entity_type);
    $entity = $storage->create();
    $entity->summary_field->value = $value = $this->randomMachineName();
    $entity->summary_field->summary = $summary = $this->randomMachineName();
    $entity->summary_field->format = NULL;
    $entity->name->value = $this->randomMachineName();
    $entity->save();

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