getFieldNames example

$violations = $exception->getViolations();
    $entity_violations = $violations->getEntityViolations();
    foreach ($entity_violations as $violation) {
      /** @var \Symfony\Component\Validator\ConstraintViolation $violation */
      $error['detail'] = 'Entity is not valid: '
        . $violation->getMessage();
      $error['source']['pointer'] = '/data';
      $errors[] = $error;
    }

    $entity = $violations->getEntity();
    foreach ($violations->getFieldNames() as $field_name) {
      $field_violations = $violations->getByField($field_name);
      $cardinality = $entity->get($field_name)
        ->getFieldDefinition()
        ->getFieldStorageDefinition()
        ->getCardinality();

      foreach ($field_violations as $violation) {
        /** @var \Symfony\Component\Validator\ConstraintViolation $violation */
        $error['detail'] = $violation->getPropertyPath() . ': '
          . PlainTextOutput::renderFromHtml($violation->getMessage());

        
private function restoreDBPrefix(): void
    {
        $this->db->setPrefix($this->DBPrefix);
    }

    private function showDataOfTable(string $tableName, int $limitRows, int $limitFieldValue)
    {
        CLI::write("Data of Table \"{$tableName}\":", 'black', 'yellow');
        CLI::newLine();

        $this->removeDBPrefix();
        $thead = $this->db->getFieldNames($tableName);
        $this->restoreDBPrefix();

        // If there is a field named `id`, sort by it.         $sortField = null;
        if (in_array('id', $thead, true)) {
            $sortField = 'id';
        }

        $this->tbody = $this->makeTableRows($tableName$limitRows$limitFieldValue$sortField);
        CLI::table($this->tbody, $thead);
    }

    
    // JOIN must appear prior to that JOIN. Since we're modifying a JOIN in     // place, and adding a new table, we must ensure that the new table appears     // prior to this one. So we recorded at what index we saw that table, and     // then use array_splice() to move the workspace_association table join to     // the correct position.     foreach ($move_workspace_tables as $workspace_association_table => $alias) {
      $this->moveEntityTable($query$workspace_association_table$alias);
    }

    $base_entity_table = $entity_type->isTranslatable() ? $entity_type->getDataTable() : $entity_type->getBaseTable();

    $base_fields = array_diff($table_mapping->getFieldNames($entity_type->getBaseTable())[$entity_type->getKey('langcode')]);
    $revisionable_fields = array_diff($table_mapping->getFieldNames($entity_type->getRevisionDataTable())$base_fields);

    // Go through and look to see if we have to modify fields and filters.     foreach ($query->fields as &$field_info) {
      // Some fields don't actually have tables, meaning they're formulae and       // whatnot. At this time we are going to ignore those.       if (empty($field_info['table'])) {
        continue;
      }

      // Dereference the alias into the actual table.


    /** * Generate CSV from a query result object * * @return string */
    public function getCSVFromResult(ResultInterface $query, string $delim = ',', string $newline = "\n", string $enclosure = '"')
    {
        $out = '';

        foreach ($query->getFieldNames() as $name) {
            $out .= $enclosure . str_replace($enclosure$enclosure . $enclosure$name) . $enclosure . $delim;
        }

        $out = substr($out, 0, -strlen($delim)) . $newline;

        // Next blast through the result array and build out the rows         while ($row = $query->getUnbufferedRow('array')) {
            $line = [];

            foreach ($row as $item) {
                $line[] = $enclosure . str_replace($enclosure$enclosure . $enclosure$item ?? '') . $enclosure;
            }

    protected function getModelFields($model$alias = null)
    {
        $metaData = $this->getManager()->getClassMetadata($model);
        $fields = $metaData->getFieldNames();
        $fields = array_combine($fields$fields);

        if ($alias) {
            foreach ($fields as &$field) {
                $field = [
                    'alias' => $alias . '.' . $field,
                    'type' => $metaData->getTypeOfField($field),
                ];
            }
        }

        


        return $data;
    }

    private function getEntitySearchFields(string $entity): array
    {
        $entityManager = $this->get(ModelManager::class);
        $metaData = $entityManager->getClassMetadata($entity);

        $fields = array_filter(
            $metaData->getFieldNames(),
            static function D$field) use ($metaData) {
                $type = $metaData->getTypeOfField($field);

                return \in_array($type['string', 'text', 'decimal', 'float']);
            }
        );

        if (empty($fields)) {
            return $metaData->getFieldNames();
        }

        
$form_state->setError($form$violation->getMessage());
    }

    $this->flagWidgetsErrorsFromViolations($violations$form$form_state);
  }

  /** * {@inheritdoc} */
  public function flagWidgetsErrorsFromViolations(EntityConstraintViolationListInterface $violations, array &$form, FormStateInterface $form_state) {
    $entity = $violations->getEntity();
    foreach ($violations->getFieldNames() as $field_name) {
      // Only show violations for fields that actually appear in the form, and       // let the widget assign the violations to the correct form elements.       if ($widget = $this->getRenderer($field_name)) {
        $field_violations = $this->movePropertyPathViolationsRelativeToField($field_name$violations->getByField($field_name));
        $widget->flagErrors($entity->get($field_name)$field_violations$form$form_state);
      }
    }
  }

  /** * Moves the property path to be relative to field level. * * @param string $field_name * The field name. * @param \Symfony\Component\Validator\ConstraintViolationListInterface $violations * The violations. * * @return \Symfony\Component\Validator\ConstraintViolationList * A new constraint violation list with the changed property path. */

  protected function mapFromStorageRecords(array $records$load_from_revision = FALSE) {
    if (!$records) {
      return [];
    }

    // Get the names of the fields that are stored in the base table and, if     // applicable, the revision table. Other entity data will be loaded in     // loadFromSharedTables() and loadFromDedicatedTables().     $field_names = $this->tableMapping->getFieldNames($this->baseTable);
    if ($this->revisionTable) {
      $field_names = array_unique(array_merge($field_names$this->tableMapping->getFieldNames($this->revisionTable)));
    }

    $values = [];
    foreach ($records as $id => $record) {
      $values[$id] = [];
      // Skip the item delta and item value levels (if possible) but let the       // field assign the value as suiting. This avoids unnecessary array       // hierarchies and saves memory here.       foreach ($field_names as $field_name) {
        

  public function testGetFieldNames() {
    // The storage definitions are only used in getColumnNames() so we do not     // need to provide any here.     $table_mapping = new TestDefaultTableMapping($this->entityType, []);

    // Test that requesting the list of field names for a table for which no     // fields have been added does not fail.     $this->assertSame([]$table_mapping->getFieldNames('foo'));

    $return = $table_mapping->setFieldNames('foo', ['id', 'name', 'type']);
    $this->assertSame($table_mapping$return);
    $expected = ['id', 'name', 'type'];
    $this->assertSame($expected$table_mapping->getFieldNames('foo'));
    $this->assertSame([]$table_mapping->getFieldNames('bar'));

    $return = $table_mapping->setFieldNames('bar', ['description', 'owner']);
    $this->assertSame($table_mapping$return);
    $expected = ['description', 'owner'];
    $this->assertSame($expected$table_mapping->getFieldNames('bar'));
    
$this->dataCache['field_names'][$table][] = $row[$key];
        }

        return $this->dataCache['field_names'][$table];
    }

    /** * Determine if a particular field exists */
    public function fieldExists(string $fieldName, string $tableName): bool
    {
        return in_array($fieldName$this->getFieldNames($tableName), true);
    }

    /** * Returns an object with field data * * @return stdClass[] */
    public function getFieldData(string $table)
    {
        return $this->_fieldData($this->protectIdentifiers($table, true, false, false));
    }

    
foreach ($new_violations as $violation) {
      $this->add($violation);
    }
    return $this;
  }

  /** * {@inheritdoc} */
  public function filterByFieldAccess(AccountInterface $account = NULL) {
    $filtered_fields = [];
    foreach ($this->getFieldNames() as $field_name) {
      if (!$this->entity->get($field_name)->access('edit', $account)) {
        $filtered_fields[] = $field_name;
      }
    }
    return $this->filterByFields($filtered_fields);
  }

  /** * {@inheritdoc} */
  public function findByCodes(string|array $codes)static {
    
 . " FROM DUAL\n";
        }

        return str_replace('{:_table_:}', $data$sql);
    }

    /** * Gets column names from a select query */
    protected function fieldsFromQuery(string $sql): array
    {
        return $this->db->query('SELECT * FROM (' . $sql . ') "_u_" WHERE ROWNUM = 1')->getFieldNames();
    }
}
$data = 'VALUES ' . implode(', ', $this->formatValues($values)) . "\n";
        }

        return str_replace('{:_table_:}', $data$sql);
    }

    /** * Gets column names from a select query */
    protected function fieldsFromQuery(string $sql): array
    {
        return $this->db->query('SELECT TOP 1 * FROM (' . $sql . ') _u_')->getFieldNames();
    }
}
$this->QBSet                       = [];
        }

        return $this;
    }

    /** * Gets column names from a select query */
    protected function fieldsFromQuery(string $sql): array
    {
        return $this->db->query('SELECT * FROM (' . $sql . ') _u_ LIMIT 1')->getFieldNames();
    }

    /** * Converts value array of array to array of strings */
    protected function formatValues(array $values): array
    {
        return array_map(static fn ($index) => '(' . implode(',', $index) . ')', $values);
    }

    /** * Compiles batch insert strings and runs the queries * * @param array|object|null $set a dataset * * @return false|int|string[] Number of rows inserted or FALSE on failure, SQL array when testMode */
public function getTableNames() {
    return array_unique(array_merge(array_keys($this->fieldNames)array_keys($this->extraColumns)));
  }

  /** * {@inheritdoc} */
  public function getAllColumns($table_name) {
    if (!isset($this->allColumns[$table_name])) {
      $this->allColumns[$table_name] = [];

      foreach ($this->getFieldNames($table_name) as $field_name) {
        $this->allColumns[$table_name] = array_merge($this->allColumns[$table_name]array_values($this->getColumnNames($field_name)));
      }

      // There is just one field for each dedicated storage table, thus       // $field_name can only refer to it.       if (isset($field_name) && $this->requiresDedicatedTableStorage($this->fieldStorageDefinitions[$field_name])) {
        // Unlike in shared storage tables, in dedicated ones field columns are         // positioned last.         $this->allColumns[$table_name] = array_merge($this->getExtraColumns($table_name)$this->allColumns[$table_name]);
      }
      else {
        
Home | Imprint | This part of the site doesn't use cookies.