Grayside.Org - cck http://grayside.org/category/terms/cck en Spaces Integrating a CCK Field http://grayside.org/2010/07/spaces-integrating-cck-field <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>I wanted to make a <span class="caps">CCK</span> Field available only when a given feature was enabled. It turns out it&#8217;s really easy.</p> <p><span class="caps">CCK</span> comes with a <em>hook_field_access()</em> hook (see <a href="http://api.lullabot.com/content_access">content_access()</a>). Any implementation of this function that returns <span class="caps">FALSE</span> for a given field results in that field being denied to the user.</p> <p>By implementing this function with a <a href="http://drupal.org/project/spaces">Spaces</a> <span class="caps">API</span> call instead of the content_permissions module approach of a new, field-specific permission, all kinds of magic becomes possible.</p> <p>Read on for demonstration code.</p> <div class="geshifilter"> <div class="php geshifilter-php" style="font-family:monospace;"> <pre style="font-family: monospace; font-weight: normal; font-style: normal"><span style="color: #009933; font-style: italic;">/** &nbsp;* Implementation of hook_field_access(). &nbsp;* Allow View/Edit access to 'field_my_cck_field' only when 'feature_name' is enabled. &nbsp;*/</span> <span style="color: #000000; font-weight: bold;">function</span> custom_field_access<span style="color: #009900;">&#40;</span><span style="color: #000088;">$op</span><span style="color: #339933;">,</span> <span style="color: #000088;">$field</span><span style="color: #339933;">,</span> <span style="color: #000088;">$account</span><span style="color: #339933;">,</span> <span style="color: #000088;">$node</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;"><span class="caps">NULL</span></span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; <span style="color: #666666; font-style: italic;">// Be sure not to affect other fields.</span> &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'field_name'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'field_my_cck_field'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;"><span class="caps">TRUE</span></span><span style="color: #339933;">;</span> &nbsp; <span style="color: #009900;">&#125;</span> &nbsp; &nbsp; <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$op</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'edit'</span><span style="color: #339933;">:</span> &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'view'</span><span style="color: #339933;">:</span> &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Make access contingent on whether a given feature is enabled in the current space, such as atrium_book.</span> &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> spaces_access_feature<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'view'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'feature_name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span></pre></div> </div> <p><strong><span class="caps">EDIT</span>: <a href="http://drupal.org/node/887272">Issue posted</a> to the Spaces queue with patch to add this functionality generically for all&nbsp;fields.</strong></p> </div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Terms:&nbsp;</div><div class="field-items"><div class="field-item even"><a href="/category/terms/cck">cck</a></div><div class="field-item odd"><a href="/category/terms/openatrium">openatrium</a></div><div class="field-item even"><a href="/category/terms/access-control">access control</a></div><div class="field-item odd"><a href="/category/terms/spaces">spaces</a></div></div></div> Mon, 26 Jul 2010 20:25:09 +0000 Grayside 86 at http://grayside.org http://grayside.org/2010/07/spaces-integrating-cck-field#comments Remove CCK Fields from the Node Form http://grayside.org/2009/11/remove-cck-fields-node-form <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>There is a fine tutorial on drupal.org describing <a href="http://drupal.org/node/357328">How to set the disabled attribute of a <span class="caps">CCK</span> field</a> on your node add/edit form. All that does is deactivate the input widget without removing the clutter. Let&#8217;s get rid of the form elements entirely.</p> <p>To actually remove the field from the input form, change the <tt>_mysnippet_fix_disabled()</tt> function to the following:</p> <div class="geshifilter"> <div class="text geshifilter-text" style="font-family:monospace;"> <pre style="font-family: monospace; font-weight: normal; font-style: normal">function _mysnippet_set_denied(&amp;$elements) { &amp;nbsp; &nbsp;foreach (element_children($elements) as $key) { &amp;nbsp;&amp;nbsp;&amp;nbsp; &nbsp;if (isset($elements[$key]) &amp;&amp; $elements[$key]) { &amp;nbsp;&amp;nbsp;&amp;nbsp; &nbsp; // Recurse through all children elements. &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &nbsp; &nbsp; _mysnippet_set_denied($elements[$key]); &amp;nbsp;&amp;nbsp;&amp;nbsp; &nbsp; } &amp;nbsp; } &amp;nbsp; $elements['#access'] = FALSE; }</pre></div> </div> </div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Terms:&nbsp;</div><div class="field-items"><div class="field-item even"><a href="/taxonomy/term/1">drupal</a></div><div class="field-item odd"><a href="/taxonomy/term/3">how-to</a></div><div class="field-item even"><a href="/category/terms/cck">cck</a></div><div class="field-item odd"><a href="/category/terms/node-form">node-form</a></div></div></div> Thu, 12 Nov 2009 23:05:04 +0000 Grayside 46 at http://grayside.org http://grayside.org/2009/11/remove-cck-fields-node-form#comments CCK Fields and the Open Atrium Node Form http://grayside.org/2009/11/cck-fields-and-open-atrium-node-form <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p><a href="http://openatrium.com">OpenAtrium</a> has some pretty slick styling of it&#8217;s node add/edit form. Unfortunately, when you add a <a href="http://drupal.org/project/cck"><span class="caps">CCK</span></a> field to it, you get something comparatively under-styled and in the main column of the form.</p> <p>If you want to get that slick styling and move the <span class="caps">CCK</span> fields to the right, try the following:</p> <ol> <li>Go to <tt>admin/build/modules</tt> and enable the <em>Fieldgroup</em> module under <span class="caps">CCK</span>.</li> <li>Go to the <tt>Manage Fields</tt> page for your content type. Create a new group, the machine name starting as <tt>group_sidebar</tt>.</li> <li>Move your <span class="caps">CCK</span> fields under that group.</li> </ol> <p>VoilĂ ! Make it collapsible as you&nbsp;like.</p> </div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Terms:&nbsp;</div><div class="field-items"><div class="field-item even"><a href="/taxonomy/term/1">drupal</a></div><div class="field-item odd"><a href="/category/terms/cck">cck</a></div><div class="field-item even"><a href="/category/terms/node-form">node-form</a></div><div class="field-item odd"><a href="/category/terms/openatrium">openatrium</a></div></div></div> Wed, 11 Nov 2009 00:04:09 +0000 Grayside 44 at http://grayside.org http://grayside.org/2009/11/cck-fields-and-open-atrium-node-form#comments Field Permissions Plus http://grayside.org/field-permissions-plus <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>This <a href="http://drupal.org">Drupal</a> <a href="http://drupal.org/project/field_permissions_plus">module</a> provides a more flexible framework from granting and restricting access to the content of <span class="caps">CCK</span> fields.</p> <p>It provides a simple framework by which you can create multiple modules which cooperate in finding some method of granting access to site users, as opposed to <span class="caps">CCK</span>&#8217;s core permission scheme in which field access modules are effectively looking for ways to deny access.</p> <p>Field Permissions Plus makes Field security behave more akin to the rest of the Drupal Permissions world.</p> <h2>Content Permissions Doesn&#8217;t Play&nbsp;Nice?!</h2> <p>Well, Content Permissions is fine. But it implements <span class="caps">CCK</span>&#8217;s hook_field_permissions(), and that function is just looking for an excuse to deny access. By replacing it, it becomes possible to create complex permission schemes with a positive perspective- and a sparse grid of checkboxes.</p> <h2>Different from the&nbsp;Competitors</h2> <p><a href="http://drupal.org/project/cck_private_fields"><span class="caps">CCK</span> Private Fields</a> and <a href="http://drupal.org/project/cck_field_privacy"><span class="caps">CCK</span> Field Privacy</a> both operate based on node-by-node approvals, user relationships, and so on. This module provides static permissions.</p> <h2>Why the&nbsp;Name?</h2> <p>This module was partially inspired by <a href="http://drupal.org/node/363950">#323950 Edit own field permission</a>. In that thread, creating a &#8220;Content Permissions Plus&#8221; was proposed to solve the problem, because it is too niche a case to integrate into <span class="caps">CCK</span> directly. To avoid the confusion of a project specifying Content Permissions, and developer confusion with the <span class="caps">CCK</span>&#8217;s <span class="caps">API</span>, Field Permissions Plus was named. The &#8220;plus&#8221; is all about the additive nature of the permissions it provides.</p> <ul> <li> {{dp:field_permissions_plus|Field Permissions&nbsp;Plus}}</li> <li>&nbsp;{{dp:cck|<span class="caps">CCK</span>}}</li> </ul> </div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Terms:&nbsp;</div><div class="field-items"><div class="field-item even"><a href="/taxonomy/term/1">drupal</a></div><div class="field-item odd"><a href="/taxonomy/term/7">module</a></div><div class="field-item even"><a href="/category/terms/cck">cck</a></div><div class="field-item odd"><a href="/category/terms/fields">fields</a></div><div class="field-item even"><a href="/category/terms/permissions">permissions</a></div><div class="field-item odd"><a href="/category/terms/field-permissions-plus">field-permissions-plus</a></div></div></div> Wed, 23 Sep 2009 20:03:39 +0000 Grayside 40 at http://grayside.org http://grayside.org/field-permissions-plus#comments Field Permissions Plus: 2.x Already?! http://grayside.org/2009/09/field-permissions-plus-2x-already <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p><a href="http://drupal.org/project/field_permissions_plus">Field Permissions Plus</a> has barely been released, but <span class="caps">FPP</span> 6.x-2.x-dev is already making progress.</p> <p>Tonight, a new release will be packaged that separates the View/Edit Own functionality from the core of <span class="caps">FPP</span>, creating a new sub-module dubbed <strong>Own Field Access</strong>. If you decide to test the development version, be sure to enable this module. If you do not uninstall <span class="caps">FPP</span> 1.x, all the permissions will still be there with all the same boxes checked.</p> <p>The biggest difference in 2.x is the new hook- <tt>hook_field_access_plus()</tt>. This function should be implemented exactly the same as <span class="caps">CCK</span>&#8217;s <tt>hook_field_access</tt>, except anything implemented with the <tt>_plus</tt> version will be deemed an exclusive, instead of inclusive, means of access.</p> <p>With Field Permissions Plus installed, you can now write two kinds of Field Access modules to create your complex Field Access&nbsp;scheme.</p> </div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Terms:&nbsp;</div><div class="field-items"><div class="field-item even"><a href="/taxonomy/term/1">drupal</a></div><div class="field-item odd"><a href="/taxonomy/term/7">module</a></div><div class="field-item even"><a href="/category/terms/cck">cck</a></div><div class="field-item odd"><a href="/category/terms/permissions">permissions</a></div><div class="field-item even"><a href="/category/terms/hook">hook</a></div></div></div> Tue, 22 Sep 2009 23:39:48 +0000 Grayside 39 at http://grayside.org Field Permissions Plus: Complex Access Schemes http://grayside.org/2009/09/field-permissions-plus-complex-access-schemes <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p><strong>This post refers to Field Permissions Plus 1.x</strong></p> <p>This <a href="http://drupal.org">Drupal</a> module provides View Own and Edit Own permissions for <span class="caps">CCK</span> fields. As a necessary step, <a href="http://drupal.org/project/field_permissions_plus">Field Permissions Plus</a> supercedes <a href="http://drupal.org/project/cck"><span class="caps">CCK</span>&#8217;s</a> Content Permissions module so the View/Edit [all] permissions it provides play nice. With this module, if you give a role the ability to View a field, or to View Own a field, they will be able to see it.</p> <p>What does View Own (or Edit Own) mean? Well, <span class="caps">CCK</span> fields are attached to nodes. If you own the node, you own the fields. This permission enables an author to see (or edit) all the field content associated with his own nodes.</p> <p>In the future, <span class="caps">FPP</span> will be expanded as a framework so other modules can provide additional permissions to expand on how a field might become editable or visible.</p> <ul> <li> {{dp:field_permissions_plus|Field Permissions&nbsp;Plus}}</li> <li>&nbsp;{{dp:cck|<span class="caps">CCK</span>}}</li> </ul> </div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Terms:&nbsp;</div><div class="field-items"><div class="field-item even"><a href="/taxonomy/term/1">drupal</a></div><div class="field-item odd"><a href="/taxonomy/term/7">module</a></div><div class="field-item even"><a href="/category/terms/cck">cck</a></div><div class="field-item odd"><a href="/category/terms/fields">fields</a></div><div class="field-item even"><a href="/category/terms/permissions">permissions</a></div></div></div> Wed, 09 Sep 2009 22:09:29 +0000 Grayside 8 at http://grayside.org