src/Charcoal/Ui/Dashboard/DashboardTrait.php
public function addWidget($widgetIdent, $widget)
    {
        if (!is_string($widgetIdent)) {
            throw new InvalidArgumentException(
                'Widget identifier needs to be a string'
            );
        }

        if ($widget instanceof UiItemInterface) {
            $this->widgets[$widgetIdent] = $widget;
        } elseif (is_array($widget)) {
            if (!isset($widget['ident'])) {
                $widget['ident'] = $widgetIdent;
            }

            $w = $this->widgetBuilder->build($widget);

            $this->widgets[$widgetIdent] = $w;
        } else {
            throw new InvalidArgumentException(
                'Can not add widget: Invalid Widget.'
            );
        }

        return $this;
    }
public function addWidget($widgetIdent, $widget)
    {
        if (!is_string($widgetIdent)) {
            throw new InvalidArgumentException(
                'Widget identifier needs to be a string'
            );
        }

        if ($widget instanceof UiItemInterface) {
            $this->widgets[$widgetIdent] = $widget;
        } elseif (is_array($widget)) {
            if (!isset($widget['ident'])) {
                $widget['ident'] = $widgetIdent;
            }

            $w = $this->widgetBuilder->build($widget);

            $this->widgets[$widgetIdent] = $w;
        } else {
            throw new InvalidArgumentException(
                'Can not add widget: Invalid Widget.'
            );
        }

        return $this;
    }
public function addWidget ( $ widgetIdent , $ widget ) { if ( ! is_string ( $ widgetIdent ) ) { throw new InvalidArgumentException ( 'Widget identifier needs to be a string' ) ; } if ( $ widget instanceof UiItemInterface ) { $ this -> widgets [ $ widgetIdent ] = $ widget ; } elseif ( is_array ( $ widget ) ) { if ( ! isset ( $ widget [ 'ident' ] ) ) { $ widget [ 'ident' ] = $ widgetIdent ; } $ w = $ this -> widgetBuilder -> build ( $ widget ) ; $ this -> widgets [ $ widgetIdent ] = $ w ; } else { throw new InvalidArgumentException ( 'Can not add widget: Invalid Widget.' ) ; } return $ this ; }
Add a widget to the dashboard.

If a widget with the same $widgetIdent already exists, it will be overridden.

@param  string                $widgetIdent The widget identifier.
@param  UiItemInterface|array $widget      The widget object or structure.
@throws InvalidArgumentException If the widget is invalid.
@return DashboardInterface Chainable
Add a widget to the dashboard .