Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pxpm committed Aug 14, 2024
1 parent 3394165 commit 24fd978
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
20 changes: 20 additions & 0 deletions src/app/Library/CrudPanel/CrudColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,26 @@ public function key(string $key)
return $this;
}

/**
* When subfields are defined, pass them through the guessing function
* so that they have label, relationship attributes, etc.
*
* @param array $subfields Subfield definition array
* @return self
*/
public function subfields($subfields)
{
$callAttributeMacro = ! isset($this->attributes['subfields']);
$this->attributes['subfields'] = $subfields;
$this->attributes = $this->crud()->makeSureColumnHasNeededAttributes($this->attributes);

if ($callAttributeMacro) {
$this->callRegisteredAttributeMacros();
}

return $this->save();
}

/**
* Remove the current column from the current operation.
*
Expand Down
2 changes: 1 addition & 1 deletion src/app/Library/CrudPanel/Traits/Columns.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ public function makeSureColumnHasNeededAttributes($column)
$column = $this->makeSureColumnHasRelationType($column);
$column = $this->makeSureColumnHasType($column);
$column = $this->makeSureColumnHasPriority($column);
$column = $this->makeSureSubfieldsHaveNecessaryAttributes($column);
$column = $this->makeSureSubfieldsHaveNecessaryAttributes($column, false);

// check if the column exists in the database (as a db column)
$column_exists_in_db = $this->hasDatabaseColumn($this->model->getTable(), $column['name']);
Expand Down
4 changes: 2 additions & 2 deletions src/app/Library/CrudPanel/Traits/FieldsProtectedMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ protected function inferFieldTypeFromRelationType($relationType)
* @param array $field Field definition array.
* @return array The improved definition of that field (a better 'subfields' array)
*/
protected function makeSureSubfieldsHaveNecessaryAttributes($field)
protected function makeSureSubfieldsHaveNecessaryAttributes($field, $includeRelationFields = true)
{
if (! isset($field['subfields']) || ! is_array($field['subfields'])) {
return $field;
Expand Down Expand Up @@ -299,7 +299,7 @@ protected function makeSureSubfieldsHaveNecessaryAttributes($field)

// when field has any of `many` relations we need to append either the pivot selector for the `ToMany` or the
// local key for the `many` relations. Other relations don't need any special treatment when used as subfields.
if (isset($field['relation_type'])) {
if (isset($field['relation_type']) && $includeRelationFields) {
switch ($field['relation_type']) {
case 'MorphToMany':
case 'BelongsToMany':
Expand Down

0 comments on commit 24fd978

Please sign in to comment.