src/Metabox/Metabox.php
public function add($field, SectionInterface $section = null): MetaboxInterface
    {
        if ($field instanceof SectionInterface) {
            $section = $field;

            if ($section->hasItems()) {
                foreach ($section->getItems() as $item) {
                    /** @var FieldTypeInterface $item */
                    $item->setOptions([
                        'group' => $section->getId()
                    ]);

                    $this->add($item, $section);
                }
            }

            return $this;
        }

        $field->setLocale($this->getLocale());
        $field->setPrefix($this->getPrefix());

        if (is_null($section)) {
            if ($this->repository()->hasGroup($field->getOption('group'))) {
                $section = $this->repository()->getGroup($field->getOption('group'));
            } else {
                $section = new Section($field->getOption('group'));
            }
            $section->addItem($field);
        }

        $this->repository()->addField($field, $section);

        return $this;
    }
public function add($field, SectionInterface $section = null): MetaboxInterface
    {
        if ($field instanceof SectionInterface) {
            $section = $field;

            if ($section->hasItems()) {
                foreach ($section->getItems() as $item) {
                    /** @var FieldTypeInterface $item */
                    $item->setOptions([
                        'group' => $section->getId()
                    ]);

                    $this->add($item, $section);
                }
            }

            return $this;
        }

        $field->setLocale($this->getLocale());
        $field->setPrefix($this->getPrefix());

        if (is_null($section)) {
            if ($this->repository()->hasGroup($field->getOption('group'))) {
                $section = $this->repository()->getGroup($field->getOption('group'));
            } else {
                $section = new Section($field->getOption('group'));
            }
            $section->addItem($field);
        }

        $this->repository()->addField($field, $section);

        return $this;
    }
public function add ( $ field , SectionInterface $ section = null ) : MetaboxInterface { if ( $ field instanceof SectionInterface ) { $ section = $ field ; if ( $ section -> hasItems ( ) ) { foreach ( $ section -> getItems ( ) as $ item ) { /** @var FieldTypeInterface $item */ $ item -> setOptions ( [ 'group' => $ section -> getId ( ) ] ) ; $ this -> add ( $ item , $ section ) ; } } return $ this ; } $ field -> setLocale ( $ this -> getLocale ( ) ) ; $ field -> setPrefix ( $ this -> getPrefix ( ) ) ; if ( is_null ( $ section ) ) { if ( $ this -> repository ( ) -> hasGroup ( $ field -> getOption ( 'group' ) ) ) { $ section = $ this -> repository ( ) -> getGroup ( $ field -> getOption ( 'group' ) ) ; } else { $ section = new Section ( $ field -> getOption ( 'group' ) ) ; } $ section -> addItem ( $ field ) ; } $ this -> repository ( ) -> addField ( $ field , $ section ) ; return $ this ; }
Add a field to the metabox.

@param FieldTypeInterface|SectionInterface $field
@param SectionInterface                    $section

@return MetaboxInterface
Add a field to the metabox .