當前位置: 首頁>>代碼示例>>PHP>>正文


PHP NodeInterface::getOwnerId方法代碼示例

本文整理匯總了PHP中Drupal\node\NodeInterface::getOwnerId方法的典型用法代碼示例。如果您正苦於以下問題:PHP NodeInterface::getOwnerId方法的具體用法?PHP NodeInterface::getOwnerId怎麽用?PHP NodeInterface::getOwnerId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Drupal\node\NodeInterface的用法示例。


在下文中一共展示了NodeInterface::getOwnerId方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: hook_node_access_records

/**
 * Set permissions for a node to be written to the database.
 *
 * When a node is saved, a module implementing hook_node_access_records() will
 * be asked if it is interested in the access permissions for a node. If it is
 * interested, it must respond with an array of permissions arrays for that
 * node.
 *
 * Node access grants apply regardless of the published or unpublished status
 * of the node. Implementations must make sure not to grant access to
 * unpublished nodes if they don't want to change the standard access control
 * behavior. Your module may need to create a separate access realm to handle
 * access to unpublished nodes.
 *
 * Note that the grant values in the return value from your hook must be
 * integers and not boolean TRUE and FALSE.
 *
 * Each permissions item in the array is an array with the following elements:
 * - 'realm': The name of a realm that the module has defined in
 *   hook_node_grants().
 * - 'gid': A 'grant ID' from hook_node_grants().
 * - 'grant_view': If set to 1 a user that has been identified as a member
 *   of this gid within this realm can view this node. This should usually be
 *   set to $node->isPublished(). Failure to do so may expose unpublished content
 *   to some users.
 * - 'grant_update': If set to 1 a user that has been identified as a member
 *   of this gid within this realm can edit this node.
 * - 'grant_delete': If set to 1 a user that has been identified as a member
 *   of this gid within this realm can delete this node.
 * - langcode: (optional) The language code of a specific translation of the
 *   node, if any. Modules may add this key to grant different access to
 *   different translations of a node, such that (e.g.) a particular group is
 *   granted access to edit the Catalan version of the node, but not the
 *   Hungarian version. If no value is provided, the langcode is set
 *   automatically from the $node parameter and the node's original language (if
 *   specified) is used as a fallback. Only specify multiple grant records with
 *   different languages for a node if the site has those languages configured.
 *
 * A "deny all" grant may be used to deny all access to a particular node or
 * node translation:
 * @code
 * $grants[] = array(
 *   'realm' => 'all',
 *   'gid' => 0,
 *   'grant_view' => 0,
 *   'grant_update' => 0,
 *   'grant_delete' => 0,
 *   'langcode' => 'ca',
 * );
 * @endcode
 * Note that another module node access module could override this by granting
 * access to one or more nodes, since grants are additive. To enforce that
 * access is denied in a particular case, use hook_node_access_records_alter().
 * Also note that a deny all is not written to the database; denies are
 * implicit.
 *
 * @param \Drupal\node\NodeInterface $node
 *   The node that has just been saved.
 *
 * @return
 *   An array of grants as defined above.
 *
 * @see hook_node_access_records_alter()
 * @ingroup node_access
 */
function hook_node_access_records(\Drupal\node\NodeInterface $node)
{
    // We only care about the node if it has been marked private. If not, it is
    // treated just like any other node and we completely ignore it.
    if ($node->private->value) {
        $grants = array();
        // Only published Catalan translations of private nodes should be viewable
        // to all users. If we fail to check $node->isPublished(), all users would be able
        // to view an unpublished node.
        if ($node->isPublished()) {
            $grants[] = array('realm' => 'example', 'gid' => 1, 'grant_view' => 1, 'grant_update' => 0, 'grant_delete' => 0, 'langcode' => 'ca');
        }
        // For the example_author array, the GID is equivalent to a UID, which
        // means there are many groups of just 1 user.
        // Note that an author can always view his or her nodes, even if they
        // have status unpublished.
        if ($node->getOwnerId()) {
            $grants[] = array('realm' => 'example_author', 'gid' => $node->getOwnerId(), 'grant_view' => 1, 'grant_update' => 1, 'grant_delete' => 1, 'langcode' => 'ca');
        }
        return $grants;
    }
}
開發者ID:eigentor,項目名稱:tommiblog,代碼行數:87,代碼來源:node.api.php


注:本文中的Drupal\node\NodeInterface::getOwnerId方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。