Assign an item to the given component

@param string $componentName
@param DataObject|null $item
@return $this
778688
public function setComponent($componentName, $item)
    {
        // Validate component
        $schema = static::getSchema();
        if ($class = $schema->hasOneComponent(static::class, $componentName)) {
            // Force item to be written if not by this point
            // @todo This could be lazy-written in a beforeWrite hook, but force write here for simplicity
            // https://github.com/silverstripe/silverstripe-framework/issues/7818
            if ($item && !$item->isInDB()) {
                $item->write();
            }

            // Update local ID
            $joinField = $componentName . 'ID';
            $this->setField($joinField, $item ? $item->ID : null);
            // Update Class (Polymorphic has_one)
            // Extract class name for polymorphic relations
            if ($class === self::class) {
                $this->setField($componentName . 'Class', $item ? get_class($item) : null);
            }
        } elseif ($class = $schema->belongsToComponent(static::class, $componentName)) {
            if ($item) {
                // For belongs_to, add to has_one on other component
                $joinField = $schema->getRemoteJoinField(static::class, $componentName, 'belongs_to', $polymorphic);
                if (!$polymorphic) {
                    $joinField = substr($joinField, 0, -2);
                }
                $item->setComponent($joinField, $this);
            }
        } else {
            throw new InvalidArgumentException(
                "DataObject->setComponent(): Could not find component '$componentName'."
            );
        }

        $this->components[$componentName] = $item;
        return $this;
    }
597969
public function setItem(\Wucdbm\Bundle\MenuBuilderBundle\Entity\MenuItem $item) {
        $this->item = $item;

        return $this;
    }
565964
public function add(Component $element)
    {
        $this->elements[] = $element;
        $this->indentations[] = $this->currentIndentation;

        if ($element instanceof LabeledParagraph) {
            $this->alignment->add($element, $this->currentIndentation);
            $element->setAlignment($this->alignment);
        }

        return $this;
    }
768034
public function setComponents(ComponentCollection $components)
    {
        return parent::setComponents($components->map(function (Component $component) {
            return $component->setZone($this);
        }));
    }
308148
public function createPropertyAssignment(string $propertyName): Assign
    {
        $variable = new Variable($propertyName);

        return $this->createPropertyAssignmentWithExpr($propertyName, $variable);
    }
173924
public static function delete_instances($component, $itemtype = null, $contextid = null) {
        global $DB;

        $sql = "SELECT ti.*, t.name, t.rawname, t.isstandard
                  FROM {tag_instance} ti
                  JOIN {tag} t
                    ON ti.tagid = t.id
                 WHERE ti.component = :component";
        $params = array('component' => $component);
        if (!is_null($contextid)) {
            $sql .= " AND ti.contextid = :contextid";
            $params['contextid'] = $contextid;
        }
        if (!is_null($itemtype)) {
            $sql .= " AND ti.itemtype = :itemtype";
            $params['itemtype'] = $itemtype;
        }

        if ($taginstances = $DB->get_records_sql($sql, $params)) {
            static::delete_instances_as_record($taginstances);
        }
    }
188701
public function addItem(Item $item)
    {
        $itemUUID = $item->composeUUID();

        $this->elementsToUpdate[$itemUUID] = $item;
        unset($this->elementsToDelete[$itemUUID]);
    }
1345461
public function removeItem(ItemInterface $item)
    {
        $this->itemsChanged = true;
        $this->entity->removeItem($item);

        return $this;
    }
73966
public function setComponentType(ComponentTypeInterface $componentType)
    {
        $this->componentTypeId = $componentType->getId();

        return parent::setComponentType($componentType);
    }
597328
public function addItem(ItemInterface $item)
    {
        $item->setGrid($this);
        $this->items[] = $item;

        return $this;
    }
1186944
public function set(ItemInterface $item)
    {
        $id = $item->getId();
        $collectionName = $item->getCollection();

        $this->items[$id] = $item;

        if (isset($this->idCollections[$id]) && $this->idCollections[$id] !== $collectionName) {
            throw new \RuntimeException(sprintf('The item with id: "%s" has been registered previously with another collection.', $id));
        }

        if (isset($this->itemCollections[$collectionName]) === false) {
            $this->itemCollections[$collectionName] = [];
        }

        $this->itemCollections[$collectionName][$id] = $item;
        $this->idCollections[$id] = $collectionName;
    }
290059
protected function setError($error, $componentName = Doozr_Form_Service_Constant::ERROR_IDENTIFIER_FORM)
    {
        // Check that each component can have more than one error at once ...
        if (!isset($this->error[$componentName])) {
            $this->error[$componentName] = [];
        }

        $this->error[$componentName][] = $error;
    }
365972
final public function getComponent(string $componentName = null) : IColumnComponent
    {
        if ($componentName === null) {
            if ($this->hasSingleComponent()) {
                return reset($this->components);
            } else {
                throw InvalidArgumentException::format(
                    'Must supply component name for %s \'%s\' with more than one component: expecting one of (%s), null given',
                    static::$debugType, $this->name, Debug::formatValues(array_keys($this->components))
                );
            }
        }

        if (!isset($this->components[$componentName])) {
            throw InvalidArgumentException::format(
                'Invalid component name for %s \'%s\': expecting one of (%s), %s given',
                static::$debugType, $this->name, Debug::formatValues(array_keys($this->components)), $componentName
            );
        }

        return $this->components[$componentName];
    }
895444
public static function display_name($component, $itemtype) {
        $identifier = 'tagarea_' . clean_param($itemtype, PARAM_STRINGID);
        if ($component === 'core') {
            $component = 'tag';
        }
        return new lang_string($identifier, $component);
    }
735498
public function removeItem(Item $item)
    {
        if ($this->items->contains($item)) {
            $this->items->removeElement($item);
            $item->removeGenre($this);
        }

        return $this;
    }
858965
public static function normalize_componentname($componentname) {
        list($plugintype, $pluginname) = self::normalize_component($componentname);
        if ($plugintype === 'core' && is_null($pluginname)) {
            return $plugintype;
        }
        return $plugintype . '_' . $pluginname;
    }
559926
function addComponent(Component, options) {
                var name = options.name,
                    container = options.container;

                if (name === undefined) {
                    throw 'you have to define data.name for component.';
                } else if (container === undefined) {
                    throw 'You have to define container for component.';
                } else if (this.children[name] !== undefined) {
                    throw 'Component using name:' + name + '! already defined.';
                }
                var component = this.setComponent(Component, options),
                    instance = component.run(options.container);
                instance.setContext(this.context);
                this.children[name] = instance;
                return instance;
            }