Remove last field from end of array
@throws \OutOfRangeException if array is empty
@return NamedBuilder Field array config or Builder
163993
public function popField()
    {
        if ($this->getCount() > 0) {
            $fields = $this->removeFieldAtIndex($this->getCount() - 1);
            return $fields[0];
        }

        throw new \OutOfRangeException("Can't call popField when the field count is 0");
    }
444181
public function end(): QueryBuilderInterface
    {
        if (null === $this->node = $this->node->getParent()) {
            throw new \Exception(sprintf('You cannot call %s on main node', __FUNCTION__));
        }

        return $this;
    }
775059
protected function getNewDeletedAtField()
    {
        $field = current(FieldTransformer::fromString('deleted_at'));
        $field->isDate = true;
        $field->dataType = 'datetime';
        $field->dateFormat = Config::getDateTimeFormat();

        return $field;
    }
530184
public function getChildKeys(): array
    {
        $snapshot = $this->shallow()->getSnapshot();

        if (\is_array($value = $snapshot->getValue())) {
            return array_keys($value);
        }

        throw new OutOfRangeException(sprintf('%s has no children with keys', $this));
    }
373495
public function compactEditBuilder()
    {
        if ($this->relationships == 0 && $this->enum == 0) {
            return '';
        } else {
            $compact = '';
            if ($this->relationships > 0) {
                foreach ($this->fields as $field) {
                    if ($field->type == 'relationship') {
                        $compact .= ', "' . $field->relationship_name . '"';
                    }
                }
            }
            if ($this->enum > 0) {
                foreach ($this->fields as $field) {
                    if ($field->type == 'enum') {
                        $compact .= ', "' . $field->title . '"';
                    }
                }
            }

            return $compact;
        }
    }
566397
public function delete_many()
        {
            // Build and return the full DELETE statement by concatenating
            // the results of calling each separate builder method.
            $query = $this->_joinIfNotEmpty(" ", array(
                "DELETE FROM",
                $this->_quoteIdentifier($this->_table_name),
                $this->_buildWhere(),
            ));

            return self::_execute($query, $this->_values, $this->_connection_name);
        }
958975
public function end() {
		list(, $options, $template) = $this->_defaults(__FUNCTION__, null, []);
		$params = compact('options', 'template');

		$result = Filters::run($this, __FUNCTION__, $params, function($params) {
			$this->_bindingOptions = [];
			return $this->_render('end', $params['template'], []);
		});
		unset($this->_binding);
		$this->_binding = null;
		return $result;
	}
839054
public function truncate()
    {
        $config = $this->getConfig();
        $config->last_id = 0;
        $this->databaseConfig->put($config);
        $this->documentEntries = [];
        $this->databaseDocument->put([]);
        return $this->setFields();
    }
716950
public function endSlot()
    {
        last($this->componentStack);

        $currentSlot = array_pop(
            $this->slotStack[$this->currentComponent()]
        );

        $this->slots[$this->currentComponent()]
                    [$currentSlot] = new HtmlString(trim(ob_get_clean()));
    }
829580
public function endMacro()
    {
        $macro = explode(PHP_EOL, $this->trimSpaces(trim(ob_get_clean())));

        $this->macros[array_pop($this->macroStack)] = $macro;
    }
1326079
public function clear()
    {
        $this->unknown = "";
        foreach ($this->desc->getField() as $field) {
            $setter = $field->getSetter();
            if ($field->isMap()) {
                $message_type = $field->getMessageType();
                $key_field = $message_type->getFieldByNumber(1);
                $value_field = $message_type->getFieldByNumber(2);
                switch ($value_field->getType()) {
                    case GPBType::MESSAGE:
                    case GPBType::GROUP:
                        $map_field = new MapField(
                            $key_field->getType(),
                            $value_field->getType(),
                            $value_field->getMessageType()->getClass());
                        $this->$setter($map_field);
                        break;
                    case GPBType::ENUM:
                        $map_field = new MapField(
                            $key_field->getType(),
                            $value_field->getType(),
                            $value_field->getEnumType()->getClass());
                        $this->$setter($map_field);
                        break;
                    default:
                        $map_field = new MapField(
                            $key_field->getType(),
                            $value_field->getType());
                        $this->$setter($map_field);
                        break;
                }
            } else if ($field->getLabel() === GPBLabel::REPEATED) {
                switch ($field->getType()) {
                    case GPBType::MESSAGE:
                    case GPBType::GROUP:
                        $repeated_field = new RepeatedField(
                            $field->getType(),
                            $field->getMessageType()->getClass());
                        $this->$setter($repeated_field);
                        break;
                    case GPBType::ENUM:
                        $repeated_field = new RepeatedField(
                            $field->getType(),
                            $field->getEnumType()->getClass());
                        $this->$setter($repeated_field);
                        break;
                    default:
                        $repeated_field = new RepeatedField($field->getType());
                        $this->$setter($repeated_field);
                        break;
                }
            } else if ($field->getOneofIndex() !== -1) {
                $oneof = $this->desc->getOneofDecl()[$field->getOneofIndex()];
                $oneof_name = $oneof->getName();
                $this->$oneof_name = new OneofField($oneof);
            } else if ($field->getLabel() === GPBLabel::OPTIONAL) {
                switch ($field->getType()) {
                    case GPBType::DOUBLE   :
                    case GPBType::FLOAT    :
                        $this->$setter(0.0);
                        break;
                    case GPBType::INT32    :
                    case GPBType::FIXED32  :
                    case GPBType::UINT32   :
                    case GPBType::SFIXED32 :
                    case GPBType::SINT32   :
                    case GPBType::ENUM     :
                        $this->$setter(0);
                        break;
                    case GPBType::BOOL     :
                        $this->$setter(false);
                        break;
                    case GPBType::STRING   :
                    case GPBType::BYTES    :
                        $this->$setter("");
                        break;
                    case GPBType::GROUP    :
                    case GPBType::MESSAGE  :
                        $null = null;
                        $this->$setter($null);
                        break;
                }
                if (PHP_INT_SIZE == 4) {
                    switch ($field->getType()) {
                        case GPBType::INT64:
                        case GPBType::UINT64:
                        case GPBType::FIXED64:
                        case GPBType::SFIXED64:
                        case GPBType::SINT64:
                            $this->$setter("0");
                    }
                } else {
                    switch ($field->getType()) {
                        case GPBType::INT64:
                        case GPBType::UINT64:
                        case GPBType::FIXED64:
                        case GPBType::SFIXED64:
                        case GPBType::SINT64:
                            $this->$setter(0);
                    }
                }
            }
        }
    }
618609
public function remove() {
        if (is_array($this->_fields)) {
            $this->_fields = implode($fields, ', ');
        }
        
        // Build Select Command
        $sql_query = 'DELETE FROM ' . $this->_table;
        
        // Where statements
        if (count($this->_where)) {
            $sql_query .= ' WHERE ';
            $sql_query .= implode($this->_where, ' AND ');
            
            // or statements
            if (count($this->_or)) {
                $sql_query .= ' OR ';
                $sql_query .= implode($this->_or, ' AND ');
            }
        }
        
        // Set the query
        $this->_sql_query = $sql_query;
        
        return $this;
    }
313133
public function prependSelect($fields = [])
    {
        if (!is_array($fields)) {
            $fields = [$fields];
        }

        $collection = collect($this->select);
        foreach ($fields as $key => $field) {
            $collection->prepend($field, is_string($key) ? $key : null);
        }

        $this->select = $collection->all();

        return $this;
    }
420436
public function getConfigTreeBuilder()
  {
    $treeBuilder = new TreeBuilder();
    $rootNode    = $treeBuilder->root('config');

    $rootNode
      ->useAttributeAsKey('name')
        ->prototype('array')
          ->children()
            ->enumNode('type')->values(array_merge(TypeEnum::toArray(), array_map('strtoupper', TypeEnum::toArray())))->defaultValue(null)->end()
            ->scalarNode('renameTo')->defaultValue(null)->end()
            ->arrayNode('children')->prototype('variable')->end()->end()
            ->arrayNode('options')
            ->addDefaultsIfNotSet()
              ->children()
                ->booleanNode('assoc')->defaultValue(true)->end()
                ->arrayNode('expected')->prototype('scalar')->end()->end()
                ->enumNode('stringValidation')->values(array_merge(StringValidationEnum::toArray(), array_map('strtoupper', StringValidationEnum::toArray())))->defaultValue(null)->end()
                ->booleanNode('strongValidation')->defaultValue(false)->end()
                ->floatNode('min')->defaultValue(null)->end()
                ->floatNode('max')->defaultValue(null)->end()
                ->integerNode('round')->defaultValue(null)->end()
                ->booleanNode('floor')->defaultValue(false)->end()
                ->booleanNode('ceil')->defaultValue(false)->end()
                ->scalarNode('returnClass')->defaultValue(null)->end()
                ->variableNode('defaultValue')->defaultValue(null)->end()
                ->scalarNode('regex')->defaultValue(null)->end()
                ->arrayNode('date')
                  ->addDefaultsIfNotSet()
                  ->children()
                    ->variableNode('expectedFormat')->defaultValue('Y-m-d')->end()
                    ->booleanNode('convertToObject')->defaultValue(false)->end()
                    ->scalarNode('convertToFormat')->defaultValue(null)->end()
                  ->end()
                ->end()
                ->booleanNode('required')->defaultValue(false)->end()
                ->arrayNode('requiredIfNotAvailable')
                ->addDefaultsIfNotSet()
                  ->children()
                    ->arrayNode('and')
                      ->prototype('scalar')->end()
                      ->defaultValue(array())
                    ->end()
                    ->arrayNode('or')
                      ->prototype('scalar')->end()
                      ->defaultValue(array())
                    ->end()
                  ->end()
                ->end()
                ->arrayNode('requiredIfAvailable')
                  ->addDefaultsIfNotSet()
                  ->children()
                    ->arrayNode('and')
                      ->prototype('scalar')->end()
                      ->defaultValue(array())
                    ->end()
                    ->arrayNode('or')
                      ->prototype('scalar')->end()
                      ->defaultValue(array())
                    ->end()
                  ->end()
                ->end()
                ->arrayNode('forbiddenIfNotAvailable')
                  ->prototype('scalar')->end()
                  ->defaultValue(array())
                ->end()
                ->arrayNode('forbiddenIfAvailable')
                  ->prototype('scalar')->end()
                  ->defaultValue(array())
                ->end()
                ->arrayNode('length')
                  ->addDefaultsIfNotSet()
                  ->children()
                    ->floatNode('min')->defaultValue(null)->end()
                    ->floatNode('max')->defaultValue(null)->end()
                  ->end()
                ->end()
                ->arrayNode('individual')->prototype('variable')->end()->end()
                ->append($this->addEventConfiguration())
              ->end()
            ->end()
          ->end()
        ->end()
      ->end();

    return $treeBuilder;
  }
10019
public function getExtraFields()
    {
        if ($this->_extraFields === null) {
            $extraFields = [];
            foreach ($this->getConfig() as $pointer => $fields) {
                if (is_array($fields)) {
                    foreach ($fields as $field) {
                        if (isset($field['extraField']) && $field['extraField']) {
                            if (!array_key_exists($field['name'], $extraFields)) {
                                $extraFields[] = $field['name'];
                            }
                        }
                    }
                }
            }
            $this->_extraFields = $extraFields;
        }

        return $this->_extraFields;
    }
621862
protected function removeReservedFields()
    {
        if (!$this->isMode(static::MODE_CREATE)) {
            return;
        }

        $reservedColumns = [
            $this->form->model()->getKeyName(),
            $this->form->model()->getCreatedAtColumn(),
            $this->form->model()->getUpdatedAtColumn(),
        ];

        $this->fields = $this->fields()->reject(function (Field $field) use ($reservedColumns) {
            return in_array($field->column(), $reservedColumns, true);
        });
    }
853678
public function setUnusedElements(array &$fieldArray)
    {
        $changedGridElements = [];
        $changedElements = [];
        $changedSubPageElements = [];

        if ($this->getTable() === 'tt_content') {
            $changedGridElements[$this->getContentUid()] = true;
            $childElementsInUnavailableColumns = [];
            $childElementsInAvailableColumns = [];
            $availableColumns = $this->getAvailableColumns($fieldArray['tx_gridelements_backend_layout'], 'tt_content');
            if (!empty($availableColumns) || $availableColumns === '0') {
                $availableColumns = GeneralUtility::intExplode(',', $availableColumns);
                $queryBuilder = $this->getQueryBuilder();
                $childElementsInUnavailableColumnsQuery = $queryBuilder
                    ->select('uid')
                    ->from('tt_content')
                    ->where(
                        $queryBuilder->expr()->andX(
                            $queryBuilder->expr()->gt('tx_gridelements_container', 0),
                            $queryBuilder->expr()->eq(
                                'tx_gridelements_container',
                                $queryBuilder->createNamedParameter((int)$this->getContentUid(), \PDO::PARAM_INT)
                            ),
                            $queryBuilder->expr()->notIn(
                                'tx_gridelements_columns',
                                $queryBuilder->createNamedParameter($availableColumns, Connection::PARAM_INT_ARRAY)
                            )
                        )
                    )
                    ->execute();
                $childElementsInUnavailableColumns = [];
                while ($childElementInUnavailableColumns = $childElementsInUnavailableColumnsQuery->fetch()) {
                    $childElementsInUnavailableColumns[] = $childElementInUnavailableColumns['uid'];
                }
                if (!empty($childElementsInUnavailableColumns)) {
                    $queryBuilder
                        ->update('tt_content')
                        ->where(
                            $queryBuilder->expr()->in(
                                'uid',
                                $queryBuilder->createNamedParameter(
                                    $childElementsInUnavailableColumns,
                                    Connection::PARAM_INT_ARRAY
                                )
                            )
                        )
                        ->set('colPos', -2)
                        ->set('backupColPos', -1)
                        ->execute();
                    array_flip($childElementsInUnavailableColumns);
                }

                $queryBuilder = $this->getQueryBuilder();
                $childElementsInAvailableColumnsQuery = $queryBuilder
                    ->select('uid')
                    ->from('tt_content')
                    ->where(
                        $queryBuilder->expr()->andX(
                            $queryBuilder->expr()->gt('tx_gridelements_container', 0),
                            $queryBuilder->expr()->eq(
                                'tx_gridelements_container',
                                $queryBuilder->createNamedParameter((int)$this->getContentUid(), \PDO::PARAM_INT)
                            ),
                            $queryBuilder->expr()->in(
                                'tx_gridelements_columns',
                                $queryBuilder->createNamedParameter($availableColumns, Connection::PARAM_INT_ARRAY)
                            )
                        )
                    )
                    ->execute();
                $childElementsInAvailableColumns = [];
                while ($childElementInAvailableColumns = $childElementsInAvailableColumnsQuery->fetch()) {
                    $childElementsInAvailableColumns[] = $childElementInAvailableColumns['uid'];
                }
                if (!empty($childElementsInAvailableColumns)) {
                    $queryBuilder
                        ->update('tt_content')
                        ->where(
                            $queryBuilder->expr()->in(
                                'uid',
                                $queryBuilder->createNamedParameter(
                                    $childElementsInAvailableColumns,
                                    Connection::PARAM_INT_ARRAY
                                )
                            )
                        )
                        ->set('colPos', -1)
                        ->set('backupColPos', -2)
                        ->execute();
                    array_flip($childElementsInAvailableColumns);
                }
            }
            $changedGridElements = $changedGridElements + $childElementsInUnavailableColumns + $childElementsInAvailableColumns;
        }

        if ($this->getTable() === 'pages') {
            $backendLayoutUid = 0;
            $backendLayoutNextLevelUid = 0;
            $rootline = BackendUtility::BEgetRootLine($this->getPageUid());
            for ($i = count($rootline); $i > 0; $i--) {
                $page = BackendUtility::getRecord(
                    'pages',
                    (int)$rootline[$i]['uid'],
                    'uid,backend_layout,backend_layout_next_level'
                );
                $selectedBackendLayoutNextLevel = (int)$page['backend_layout_next_level'];
                if ($page['uid'] === $this->getPageUid()) {
                    if ($fieldArray['backend_layout_next_level'] !== 0) {
                        // Backend layout for sub pages of the current page is set
                        $backendLayoutNextLevelUid = (int)$fieldArray['backend_layout_next_level'];
                    }
                    if ($fieldArray['backend_layout'] !== 0) {
                        // Backend layout for current page is set
                        $backendLayoutUid = $fieldArray['backend_layout'];
                        break;
                    }
                } else {
                    if ($selectedBackendLayoutNextLevel === -1 && $page['uid'] !== $this->getPageUid()) {
                        // Some previous page in our rootline sets layout_next to "None"
                        break;
                    }
                    if ($selectedBackendLayoutNextLevel > 0 && $page['uid'] !== $this->getPageUid()) {
                        // Some previous page in our rootline sets some backend_layout, use it
                        $backendLayoutUid = $selectedBackendLayoutNextLevel;
                        break;
                    }
                }
            }

            if (isset($fieldArray['backend_layout'])) {
                $availableColumns = $this->getAvailableColumns($backendLayoutUid, 'pages', $this->getPageUid());
                $availableColumns = GeneralUtility::intExplode(',', $availableColumns);
                $queryBuilder = $this->getQueryBuilder();
                $elementsInUnavailableColumnsQuery = $queryBuilder
                    ->select('uid')
                    ->from('tt_content')
                    ->where(
                        $queryBuilder->expr()->andX(
                            $queryBuilder->expr()->eq(
                                'pid',
                                $queryBuilder->createNamedParameter((int)$this->getPageUid(), \PDO::PARAM_INT)
                            ),
                            $queryBuilder->expr()->notIn(
                                'colPos',
                                $queryBuilder->createNamedParameter($availableColumns, Connection::PARAM_INT_ARRAY)
                            )
                        )
                    )
                    ->execute();
                $elementsInUnavailableColumns = [];
                while ($elementInUnavailableColumns = $elementsInUnavailableColumnsQuery->fetch()) {
                    $elementsInUnavailableColumns[] = $elementInUnavailableColumns['uid'];
                }
                if (!empty($elementsInUnavailableColumns)) {
                    $queryBuilder
                        ->update('tt_content')
                        ->where(
                            $queryBuilder->expr()->in(
                                'uid',
                                $queryBuilder->createNamedParameter(
                                    $elementsInUnavailableColumns,
                                    Connection::PARAM_INT_ARRAY
                                )
                            )
                        )
                        ->set('backupColPos', $queryBuilder->quoteIdentifier('colPos'), false)
                        ->set('colPos', -2)
                        ->execute();
                    array_flip($elementsInUnavailableColumns);
                }

                $queryBuilder = $this->getQueryBuilder();
                $elementsInAvailableColumnsQuery = $queryBuilder
                    ->select('uid')
                    ->from('tt_content')
                    ->where(
                        $queryBuilder->expr()->andX(
                            $queryBuilder->expr()->eq(
                                'pid',
                                $queryBuilder->createNamedParameter((int)$this->getPageUid(), \PDO::PARAM_INT)
                            ),
                            $queryBuilder->expr()->neq(
                                'backupColPos',
                                $queryBuilder->createNamedParameter(-2, \PDO::PARAM_INT)
                            ),
                            $queryBuilder->expr()->in(
                                'backupColPos',
                                $queryBuilder->createNamedParameter($availableColumns, Connection::PARAM_INT_ARRAY)
                            )
                        )
                    )
                    ->execute();
                $elementsInAvailableColumns = [];
                while ($elementInAvailableColumns = $elementsInAvailableColumnsQuery->fetch()) {
                    $elementsInAvailableColumns[] = $elementInAvailableColumns['uid'];
                }
                if (!empty($elementsInAvailableColumns)) {
                    $queryBuilder
                        ->update('tt_content')
                        ->where(
                            $queryBuilder->expr()->in(
                                'uid',
                                $queryBuilder->createNamedParameter(
                                    $elementsInAvailableColumns,
                                    Connection::PARAM_INT_ARRAY
                                )
                            )
                        )
                        ->set('colPos', $queryBuilder->quoteIdentifier('backupColPos'), false)
                        ->set('backupColPos', -2)
                        ->execute();
                    array_flip($elementsInAvailableColumns);
                }
                $changedElements = $elementsInUnavailableColumns + $elementsInAvailableColumns;
            }

            if (isset($fieldArray['backend_layout_next_level'])) {
                $backendLayoutUid = $backendLayoutNextLevelUid ? $backendLayoutNextLevelUid : $backendLayoutUid;
                $subPages = [];
                $this->getSubPagesRecursively($this->getPageUid(), $subPages);
                if (!empty($subPages)) {
                    $changedSubPageElements = [];
                    foreach ($subPages as $page) {
                        $availableColumns = $this->getAvailableColumns($backendLayoutUid, 'pages', $page['uid']);
                        $availableColumns = GeneralUtility::intExplode(',', $availableColumns);
                        $queryBuilder = $this->getQueryBuilder();
                        $subPageElementsInUnavailableColumnsQuery = $queryBuilder
                            ->select('uid')
                            ->from('tt_content')
                            ->where(
                                $queryBuilder->expr()->andX(
                                    $queryBuilder->expr()->eq(
                                        'pid',
                                        $queryBuilder->createNamedParameter((int)$page['uid'], \PDO::PARAM_INT)
                                    ),
                                    $queryBuilder->expr()->notIn(
                                        'colPos',
                                        $queryBuilder->createNamedParameter(
                                            $availableColumns,
                                            Connection::PARAM_INT_ARRAY
                                        )
                                    )
                                )
                            )
                            ->execute();
                        $subPageElementsInUnavailableColumns = [];
                        while ($subPageElementInUnavailableColumns = $subPageElementsInUnavailableColumnsQuery->fetch()) {
                            $subPageElementsInUnavailableColumns[] = $subPageElementInUnavailableColumns['uid'];
                        }
                        if (!empty($subPageElementsInUnavailableColumns)) {
                            $queryBuilder
                                ->update('tt_content')
                                ->where(
                                    $queryBuilder->expr()->in(
                                        'uid',
                                        $queryBuilder->createNamedParameter(
                                            $subPageElementsInUnavailableColumns,
                                            Connection::PARAM_INT_ARRAY
                                        )
                                    )
                                )
                                ->set('backupColPos', $queryBuilder->quoteIdentifier('colPos'), false)
                                ->set('colPos', -2)
                                ->execute();
                            array_flip($subPageElementsInUnavailableColumns);
                        }

                        $queryBuilder = $this->getQueryBuilder();
                        $subPageElementsInAvailableColumnsQuery = $queryBuilder
                            ->select('uid')
                            ->from('tt_content')
                            ->where(
                                $queryBuilder->expr()->andX(
                                    $queryBuilder->expr()->eq(
                                        'pid',
                                        $queryBuilder->createNamedParameter((int)$page['uid'], \PDO::PARAM_INT)
                                    ),
                                    $queryBuilder->expr()->neq(
                                        'backupColPos',
                                        $queryBuilder->createNamedParameter(-2, \PDO::PARAM_INT)
                                    ),
                                    $queryBuilder->expr()->in(
                                        'backupColPos',
                                        $queryBuilder->createNamedParameter(
                                            $availableColumns,
                                            Connection::PARAM_INT_ARRAY
                                        )
                                    )
                                )
                            )
                            ->execute();
                        $subPageElementsInAvailableColumns = [];
                        while ($subPageElementInAvailableColumns = $subPageElementsInAvailableColumnsQuery->fetch()) {
                            $subPageElementsInAvailableColumns[] = $subPageElementInAvailableColumns['uid'];
                        }
                        if (!empty($subPageElementsInAvailableColumns)) {
                            $queryBuilder
                                ->update('tt_content')
                                ->where(
                                    $queryBuilder->expr()->in(
                                        'uid',
                                        $queryBuilder->createNamedParameter(
                                            $subPageElementsInAvailableColumns,
                                            Connection::PARAM_INT_ARRAY
                                        )
                                    )
                                )
                                ->set('colPos', $queryBuilder->quoteIdentifier('backupColPos'), false)
                                ->set('backupColPos', -2)
                                ->execute();
                            array_flip($subPageElementsInAvailableColumns);
                        }

                        $changedPageElements = $subPageElementsInUnavailableColumns + $subPageElementsInAvailableColumns;
                        $changedSubPageElements = $changedSubPageElements + $changedPageElements;
                    }
                }
            }
        }

        $changedElementUids = $changedGridElements + $changedElements + $changedSubPageElements;
        if (!empty($changedElementUids)) {
            foreach ($changedElementUids as $uid => $value) {
                $this->dataHandler->updateRefIndex('tt_content', $uid);
            }
        }
    }