/** * @see elgg_create_widget * @access private * @since 1.9.0 */ public function createWidget($owner_guid, $handler, $context, $access_id = null) { if (empty($owner_guid) || empty($handler) || !$this->validateType($handler)) { return false; } $owner = get_entity($owner_guid); if (!$owner) { return false; } $widget = new \ElggWidget(); $widget->owner_guid = $owner_guid; $widget->container_guid = $owner_guid; // @todo - will this work for group widgets? if (isset($access_id)) { $widget->access_id = $access_id; } else { $widget->access_id = get_default_access(); } if (!$widget->save()) { return false; } // private settings cannot be set until \ElggWidget saved $widget->handler = $handler; $widget->context = $context; return $widget->getGUID(); }
public function addWidget($section, $guid = null, $context = 'framework') { $widget = new ElggWidget($guid); $widget->title = $this->getSectionTitle($section); $widget->name = $this->getSectionName($section); $widget->owner_guid = $this->owner_guid; $widget->container_guid = $this->guid; $widget->handler = $this->get('handler'); $widget->context = $context; $widget->section = $section; $widget->access_id = $this->access_id; if ($widget->save()) { $widget->move(1, 1); } return $widget; }
/** * Add a new widget instance * * @param int $entity_guid GUID of entity that owns this widget * @param string $handler The handler for this widget * @param string $context The page context for this widget * @param int $order The order to display this widget in * @param int $column The column to display this widget in (1, 2 or 3) * @param int $access_id If not specified, it is set to the default access level * * @return int|false Widget GUID or false on failure * @deprecated 1.8 use elgg_create_widget() */ function add_widget($entity_guid, $handler, $context, $order = 0, $column = 1, $access_id = null) { elgg_deprecated_notice('add_widget has been deprecated for elgg_create_widget', 1.8); if (empty($entity_guid) || empty($context) || empty($handler) || !widget_type_exists($handler)) { return false; } if ($entity = get_entity($entity_guid)) { $widget = new ElggWidget(); $widget->owner_guid = $entity_guid; $widget->container_guid = $entity_guid; if (isset($access_id)) { $widget->access_id = $access_id; } else { $widget->access_id = get_default_access(); } $guid = $widget->save(); // private settings cannot be set until ElggWidget saved $widget->handler = $handler; $widget->context = $context; $widget->column = $column; $widget->order = $order; return $guid; } return false; }
/** * Add a new widget that is being cloned via StickyWidgets. * * @param int $user_guid User GUID to associate this widget with * @param string $handler The handler for this widget * @param string $context The page context for this widget * @param int $order The order to display this widget in * @param int $column The column to display this widget in (1, 2 or 3) * @return true|false Depending on success */ function add_widget_via_sticky($user_guid, $handler, $context, $order = 0, $column = 1) { if (empty($user_guid) || empty($context) || empty($handler) || !widget_type_exists($handler)) { return false; } if ($user = get_user($user_guid)) { $widget = new ElggWidget(); $widget->owner_guid = $user_guid; $widget->access_id = 1; $widget->container_guid = $user_guid; $ctx = get_context(); set_context('add_sticky_widgets'); if (!$widget->save()) { set_context($ctx); return false; } set_context($ctx); $widget->handler = $handler; $widget->context = $context; $widget->column = $column; $widget->order = $order; // save_widget_location($widget, $order, $column); return true; } return false; }
/** * Add a new widget * * @param int $user_guid User GUID to associate this widget with * @param string $handler The handler for this widget * @param string $context The page context for this widget * @param int $order The order to display this widget in * @param int $column The column to display this widget in (1, 2 or 3) * @param int $access_id If not specified, it is set to the default access level * @return true|false Depending on success */ function add_widget($user_guid, $handler, $context, $order = 0, $column = 1, $access_id = null) { if (empty($user_guid) || empty($context) || empty($handler) || !widget_type_exists($handler)) { return false; } if ($user = get_user($user_guid)) { $widget = new ElggWidget(); $widget->owner_guid = $user_guid; $widget->container_guid = $user_guid; if (isset($access_id)) { $widget->access_id = $access_id; } else { $widget->access_id = get_default_access(); } if (!$widget->save()) { return false; } $widget->handler = $handler; $widget->context = $context; $widget->column = $column; $widget->order = $order; // save_widget_location($widget, $order, $column); return true; } return false; }