+
+ /**
+ * Set the pid. This is either the vanillaUid (see description in FormDataCompiler),
+ * or a pid given by pageTsConfig for inline children.
+ *
+ * @param array $result Result array
+ * @return array Modified result array
+ * @throws \UnexpectedValueException
+ */
+ protected function setPid(array $result)
+ {
+ // Set pid to vanillaUid. This can be a negative value
+ // if the record is added relative to another record.
+ $result['databaseRow']['pid'] = $result['vanillaUid'];
+
+ // In case a new inline record is created, the pid can be set to a different value
+ // by pageTsConfig, but not by userTsConfig. This overrides the above pid selection
+ // and forces the pid of new inline children.
+ $tableNameWithDot = $result['tableName'] . '.';
+ if ($result['isInlineChild'] && isset($result['pageTsConfig']['TCAdefaults.'][$tableNameWithDot]['pid'])) {
+ if (!MathUtility::canBeInterpretedAsInteger($result['pageTsConfig']['TCAdefaults.'][$tableNameWithDot]['pid'])) {
+ throw new \UnexpectedValueException(
+ 'page TSConfig setting TCAdefaults.' . $tableNameWithDot . 'pid must be a number, but given string '
+ . $result['pageTsConfig']['TCAdefaults.'][$tableNameWithDot]['pid'] . ' can not be interpreted as integer',
+ 1461598332
+ );
+ }
+ $result['databaseRow']['pid'] = (int)$result['pageTsConfig']['TCAdefaults.'][$tableNameWithDot]['pid'];
+ }
+
+ return $result;
+ }