Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
chillu committed Mar 27, 2013
2 parents 6209d1b + ccb0155 commit 538bf01
Show file tree
Hide file tree
Showing 23 changed files with 195 additions and 119 deletions.
14 changes: 14 additions & 0 deletions core/Config.php
Expand Up @@ -623,6 +623,20 @@ public function __construct() {
$this->indexing = array();
}

public function __clone() {
if (version_compare(PHP_VERSION, '5.3.7', '<')) {
// SplFixedArray causes seg faults before PHP 5.3.7
$cloned = array();
}
else {
$cloned = new SplFixedArray(self::SIZE);
}
for ($i = 0; $i < self::SIZE; $i++) {
$cloned[$i] = clone $this->cache[$i];
}
$this->cache = $cloned;
}

public function set($key, $val, $tags = array()) {
// Find an index to set at
$replacing = null;
Expand Down
55 changes: 48 additions & 7 deletions docs/en/changelogs/3.1.0.md
Expand Up @@ -33,7 +33,7 @@

## Upgrading

### Static configuration properties are now immutable, you must use Config API.
### Static properties are immutable and private, you must use Config API.

A common SilverStripe pattern is to use a static variable on a class to define a configuration parameter.
The configuration system added in SilverStripe 3.0 builds on this by using this static variable as a way
Expand Down Expand Up @@ -75,6 +75,8 @@ Here's an example on how to rewrite a common `_config.php` configuration:
SSViewer::set_theme('basic');
}

Object::add_extension('Member', 'MyMemberExtension');

The ugpraded `_config.php`:

:::php
Expand Down Expand Up @@ -106,6 +108,9 @@ The upgraded `config.yml`:
---
SSViewer:
theme: 'simple'
Member:
extensions:
MyMemberExtension
---
Only:
environment: 'live'
Expand All @@ -121,18 +126,54 @@ Some examples of changed notations (not exhaustive, there's over a hundred in to
* `Director::setBaseURL`: Use `Director.alternate_base_url` instead
* `SSViewer::setOption('rewriteHashlinks', ...)`: Use `SSViewer.rewrite_hashlinks` instead

**Important**: Please remember to upgrade the installer project as well, particularly
<div class="warning" markdown='1'>
Please remember to upgrade the installer project as well, particularly
your `.htaccess` or `web.config` files. Web access to these sensitive YAML configuration files
needs to be explicitly denied through these configuration files (see the [3.0.5 security release](/changelogs/3.0.4))
for details.

This change will also affect any visibility modifiers on `SiteTree` subclasses
in your own codebase, since those are further extended by SilverStripe core,
e.g. `ErrorPage extends Page`. Please change all "core statics" like `$db`, `$has_one`,
`$has_many`, `$many_many`, `$defaults`, etc to `private` visibility.
</div>

For more information about how to use the config system, see the ["Configuration" topic](/topic/configuration).

### Statics in custom Page classes need to be "private"

Related to the configuration change described above, many statics in core are now
marked with `private` visibility. While PHP allows making variables more visible
(e.g. from "private" to "public"), it complains if you try to restrict visibility in subclasses.
The core framework extends from the `Page` class in your own codebase (`mysite/`),
which means you need to change those statics to `private` yourself.
The same rules apply to controllers subclassd from `Page_Controller`.

Before:

:::php
<?php
class Page extends SiteTree {
static $db = array('MyVar' => 'Text');
}
class Page_Controller extends ContentController {
static $allowed_actions = array('myaction');
}

After:

:::php
<?php
class Page extends SiteTree {
private static $db = array('MyVar' => 'Text');
}
class Page_Controller extends ContentController {
private static $allowed_actions = array('myaction');
}

Most statics defined in `SiteTree` and `DataObject` are affected, for example:
`$db`, `$has_one`, `$has_many`, `$many_many`, `$defaults`, `$allowed_children`.
The same goes for statics defined in `ContentController`, e.g. `$allowed_actions`.

Classes which are not further extended by the core (e.g. all custom `DataObject` subclasses)
are not affected by this change, although we recommend to mark those inherited statics
as `private` as well, to make it clear that they should be accessed through the Config API.

### default_cast is now Text

In order to reduce the chance of accidentally allowing XSS attacks, the value of default_cast
Expand Down
6 changes: 5 additions & 1 deletion docs/en/howto/customize-cms-pages-list.md
Expand Up @@ -62,7 +62,11 @@ or across page types with common characteristics.
}
}

Now you just need to enable the extension in your [configuration file](/topics/configuration).

// mysite/_config/config.yml
LeftAndMain:
extensions:
- NewsPageHolderCMSMainExtension
- NewsPageHolderCMSMainExtension

You're all set! Don't forget to flush the caches by appending `?flush=all` to the URL.
16 changes: 10 additions & 6 deletions docs/en/howto/extend-cms-interface.md
Expand Up @@ -82,10 +82,12 @@ Create a new file called `mysite/code/BookmarkedPageExtension.php` and insert th
}
}

Enable the extension with the following line in `mysite/_config.php`:
Enable the extension in your [configuration file](/topics/configuration)

:::php
SiteTree::add_extension('BookmarkedPageExtension');
:::yml
SiteTree:
extensions:
- BookmarkedPageExtension

In order to add the field to the database, run a `dev/build/?flush=all`.
Refresh the CMS, open a page for editing and you should see the new checkbox.
Expand All @@ -106,10 +108,12 @@ Add the following code to a new file `mysite/code/BookmarkedLeftAndMainExtension
}
}

Enable the extension with the following line in `mysite/_config.php`:
Enable the extension in your [configuration file](/topics/configuration)

:::php
LeftAndMain::add_extension('BookmarkedPagesLeftAndMainExtension');
:::yml
LeftAndMain:
extensions:
- BookmarkedPagesLeftAndMainExtension

As the last step, replace the hardcoded links with our list from the database.
Find the `<ul>` you created earlier in `mysite/admin/templates/LeftAndMain.ss`
Expand Down
30 changes: 15 additions & 15 deletions docs/en/reference/dataextension.md
Expand Up @@ -13,36 +13,36 @@ Your extension will need to be a subclass of `[api:DataExtension]` or the `[api:

:::php
<?php

// mysite/code/CustomMember.php

class CustomMember extends DataExtension {

}
// mysite/code/MyMemberExtension.php
class MyMemberExtension extends DataExtension {}

This defines your own extension where you can add your own functions, database fields or other properties you want.
After you create this extension however it does not yet apply it to your object. Next you need to tell SilverStripe what
class you want to extend.

### Adding a extension to a built-in class

Sometimes you will want to add extension to classes that you didn't make. For example, you might want to add the
ForumRole extension to the `[api:Member]` object.

Sometimes you will want to add extension to classes that you can't cleanly subclass.
For example, you might want to add a `MyMemberExtension` class to the `[api:Member]` object.

:::php
ClassYouWantToOverride::add_extension('Your Class Name');
In order to active this extension, you'd add the following to your [config.yml](/topics/configuration).

:::yml
Member:
extensions:
- MyMemberExtension

For example above we want to override Member with a Custom Member so we would write the following
Alternatively, you can add extensions through PHP code as well (in your `config.php` file),
which means they can be used in conditional configuration.

:::php
// add to mysite/_config.php
Member::add_extension('CustomMember');
// Preferred notation: Through the Config API
Config::inst()->update('Member', 'extensions', array('MyMemberExtension'));
// Legacy notation: Through static class access
Member::add_extension('MyMemberExtension');

## Implementation


### Adding extra database fields

Extra database fields can be added with a extension in the same manner as if they
Expand Down
13 changes: 7 additions & 6 deletions docs/en/reference/member.md
Expand Up @@ -88,19 +88,20 @@ and another subclass for the same email-address in the address-database.
## Member Role Extension

Using inheritance to add extra behaviour or data fields to a member is limiting, because you can only inherit from 1
class. A better way is to use role extensions to add this behaviour.
class. A better way is to use role extensions to add this behaviour. Add the following to your
`[config.yml](/topics/configuration)`.

:::php
Member::add_extension('ForumRole');
// OR
Member::add_role('ForumRole');
:::yml
Member:
extensions:
- MyMemberExtension

A role extension is simply a subclass of `[api:DataExtension]` that is designed to be used to add behaviour to `[api:Member]`.
The roles affect the entire class - all members will get the additional behaviour. However, if you want to restrict
things, you should add appropriate `[api:Permission::checkMember()]` calls to the role's methods.

:::php
class ForumRole extends DataExtension {
class MyMemberExtension extends DataExtension {
/**

* Modify the field set to be displayed in the CMS detail pop-up
Expand Down
8 changes: 6 additions & 2 deletions docs/en/reference/modeladmin.md
Expand Up @@ -245,8 +245,12 @@ also another tool at your disposal: The `[api:Extension]` API.
}
}

// mysite/_config.php
MyAdmin::add_extension('MyAdminExtension');
Now enable this extension through your `[config.yml](/topics/configuration)` file.

:::yml
MyAdmin:
extensions:
- MyAdminExtension

The following extension points are available: `updateEditForm()`, `updateSearchContext()`,
`updateSearchForm()`, `updateList()`, `updateImportForm`.
Expand Down
8 changes: 5 additions & 3 deletions docs/en/reference/siteconfig.md
Expand Up @@ -24,7 +24,6 @@ Or if you want to access variables in the PHP you can do

:::php
$config = SiteConfig::current_site_config();

$config->Title


Expand All @@ -49,9 +48,12 @@ Create a mysite/code/CustomSiteConfig.php file.
}


Then add a link to your extension in the _config.php file like below.
Then activate your extension in your `[config.yml](/topics/configuration)` file.

SiteConfig::add_extension('CustomSiteConfig');
:::yml
SiteConfig:
extensions:
- CustomSiteConfig


This tells SilverStripe to add the CustomSiteConfig extension to the `[api:SiteConfig]` class.
Expand Down

0 comments on commit 538bf01

Please sign in to comment.