Merge branch 'master' of github.com:octobercms/october

This commit is contained in:
alekseybobkov 2014-05-23 18:59:35 +11:00
commit 206d7e43e4
17 changed files with 2584 additions and 1383 deletions

View File

@ -1,6 +1,11 @@
* **Build 89** (2014-05-22)
- Components have a new override method `onRender()` called before a component is rendered.
- The `{% component %}` tag now supports passing parameters that override the component properties when they are rendered.
- Calling `addJs()` and `addCss()` in components without a starting slash (/) will now reference the component directory, instead of the theme.
* **Build 87** (2014-05-21)
- Plugins can now be disabled manually by config (see config cms.disablePlugins).
- Plugins with missing dependancies are disabled by the system.
- Plugins with missing dependencies are disabled by the system.
- Fixes an issue where paid plugins could not be downloaded.
* **Build 84** (2014-05-20)

View File

@ -525,6 +525,9 @@ class FormController extends ControllerBehavior
*/
private function setModelAttributes($model, $saveData)
{
if (!is_array($saveData))
return;
$singularTypes = ['belongsTo', 'hasOne', 'morphOne'];
foreach ($saveData as $attribute => $value) {
if ($model->hasRelation($attribute) && in_array($model->getRelationType($attribute), $singularTypes))

View File

@ -69,7 +69,8 @@ hr {
margin-bottom: 15px;
}
blockquote {
margin-left: 3em;
margin-left: 1.5em !important;
padding-left: 0;
color: #777;
font-style: italic;
}

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -297,7 +297,7 @@ class Form extends WidgetBase
/**
* Programatically add fields, used internally and for extensibility.
*/
public function addFields(array $fields, $addToTab = null)
public function addFields(array $fields, $addToArea = null)
{
foreach ($fields as $name => $config) {
@ -322,7 +322,7 @@ class Form extends WidgetBase
$this->allFields[$name] = $fieldObj;
switch (strtolower($addToTab)) {
switch (strtolower($addToArea)) {
case 'primary':
$this->primaryTabs[$tab][$name] = $fieldObj;
break;

View File

@ -87,9 +87,9 @@ class ReportContainer extends WidgetBase
$this->addJs('js/reportcontainer.js');
}
/*
* Event handelrs
*/
//
// Event handlers
//
public function onUpdateWidget()
{
@ -97,8 +97,8 @@ class ReportContainer extends WidgetBase
$widget = $this->findWidgetByAlias($alias);
$this->saveWidgetProperties($alias, $widget->setProperties(
json_decode(Request::input('fields'), true)
));
json_decode(Request::input('fields'), true)
));
return [
'#'.$alias => $widget->render()
@ -204,9 +204,9 @@ class ReportContainer extends WidgetBase
$this->setWidgetsToUserPreferences($widgets);
}
/*
* Methods for the internal use
*/
//
// Methods for the internal use
//
protected function loadWidgets()
{
@ -286,16 +286,17 @@ class ReportContainer extends WidgetBase
'validationPattern' => '^[0-9]+$',
'validationMessage' => 'Please enter the widget width as a number between 1 and 10.',
'options' => [
1=>'1 column',
2=>'2 columns',
3=>'3 columns',
4=>'4 columns',
5=>'5 columns',
6=>'6 columns',
7=>'7 columns',
8=>'8 columns',
9=>'9 columns',
10=>'10 columns']
1 => '1 column',
2 => '2 columns',
3 => '3 columns',
4 => '4 columns',
5 => '5 columns',
6 => '6 columns',
7 => '7 columns',
8 => '8 columns',
9 => '9 columns',
10 => '10 columns'
]
];
$result[] = $property;

View File

@ -5,7 +5,6 @@ use Lang;
use Config;
use Cms\Classes\CodeBase;
use Cms\Classes\CmsException;
use System\Traits\PropertyContainer;
use October\Rain\Extension\Extendable;
/**
@ -16,7 +15,8 @@ use October\Rain\Extension\Extendable;
*/
abstract class ComponentBase extends Extendable
{
use PropertyContainer;
use \System\Traits\AssetMaker;
use \System\Traits\PropertyContainer;
/**
* @var string A unique identifier for this component.
@ -69,6 +69,7 @@ abstract class ComponentBase extends Extendable
$className = Str::normalizeClassName(get_called_class());
$this->dirName = strtolower(str_replace('\\', '/', $className));
$this->assetPath = Config::get('cms.pluginsDir') . dirname(dirname($this->dirName));
parent::__construct();
}
@ -83,7 +84,7 @@ abstract class ComponentBase extends Extendable
*/
public function getPath()
{
return base_path() . Config::get('cms.pluginsDir') . '/' . $this->dirName;
return base_path() . Config::get('cms.pluginsDir') . $this->dirName;
}
/**
@ -91,6 +92,11 @@ abstract class ComponentBase extends Extendable
*/
public function onRun() {}
/**
* Executed when this component is rendered on a page or layout.
*/
public function onRender() {}
/**
* Dynamically handle calls into the controller instance.
* @param string $method

View File

@ -84,7 +84,7 @@ class Controller extends BaseController
public function __construct($theme = null)
{
$this->theme = $theme ? $theme : Theme::getActiveTheme();
$this->assetPath = $this->themeUrl();
$this->assetPath = Config::get('cms.themesDir').'/'.$this->theme->getDirName();
}
/**
@ -536,8 +536,14 @@ class Controller extends BaseController
* Renders a component's default content.
* @return string Returns the component default contents.
*/
public function renderComponent($name)
public function renderComponent($name, $parameters = [])
{
if ($componentObj = $this->findComponentByName($name)) {
$componentObj->setProperties(array_merge($componentObj->getProperties(), $parameters));
if ($result = $componentObj->onRender())
return $result;
}
return $this->renderPartial($name.'::default');
}

View File

@ -12,8 +12,8 @@ class MarkupManager
{
use \October\Rain\Support\Traits\Singleton;
const EXTENSION_FILTER = 'functions';
const EXTENSION_FUNCTION = 'filters';
const EXTENSION_FILTER = 'filters';
const EXTENSION_FUNCTION = 'functions';
const EXTENSION_TOKEN_PARSER = 'tokens';
/**

View File

@ -1,8 +1,8 @@
<?php namespace Cms\Twig;
use Twig_Node;
use Twig_Node_Expression;
use Twig_Compiler;
use Twig_NodeInterface;
/**
* Represents a component node
@ -12,9 +12,9 @@ use Twig_Compiler;
*/
class ComponentNode extends Twig_Node
{
public function __construct(Twig_Node_Expression $name, $lineno, $tag = 'component')
public function __construct(Twig_NodeInterface $nodes, $paramNames, $lineno, $tag = 'component')
{
parent::__construct(['name'=>$name], [], $lineno, $tag);
parent::__construct(['nodes' => $nodes], ['names' => $paramNames], $lineno, $tag);
}
/**
@ -24,11 +24,23 @@ class ComponentNode extends Twig_Node
*/
public function compile(Twig_Compiler $compiler)
{
$compiler->addDebugInfo($this);
$compiler->write("\$context['__cms_component_params'] = [];\n");
for ($i = 1; $i < count($this->getNode('nodes')); $i++) {
$compiler->write("\$context['__cms_component_params']['".$this->getAttribute('names')[$i-1]."'] = ");
$compiler->subcompile($this->getNode('nodes')->getNode($i));
$compiler->write(";\n");
}
$compiler
->addDebugInfo($this)
->write("echo \$this->env->getExtension('CMS')->componentFunction(")
->subcompile($this->getNode('name'))
->subcompile($this->getNode('nodes')->getNode(0))
->write(", \$context['__cms_component_params']")
->write(");\n")
;
$compiler->write("unset(\$context['__cms_component_params']);\n");
}
}

View File

@ -1,7 +1,9 @@
<?php namespace Cms\Twig;
use Twig_Node;
use Twig_Token;
use Twig_TokenParser;
use Twig_Error_Syntax;
/**
* Parser for the {% component %} Twig tag.
@ -24,10 +26,35 @@ class ComponentTokenParser extends Twig_TokenParser
*/
public function parse(Twig_Token $token)
{
$lineno = $token->getLine();
$stream = $this->parser->getStream();
$name = $this->parser->getExpressionParser()->parseExpression();
$stream->expect(Twig_Token::BLOCK_END_TYPE);
return new ComponentNode($name, $token->getLine(), $this->getTag());
$paramNames = [];
$nodes = [$name];
$end = false;
while (!$end) {
$current = $stream->next();
switch ($current->getType()) {
case Twig_Token::NAME_TYPE:
$paramNames[] = $current->getValue();
$stream->expect(Twig_Token::OPERATOR_TYPE, '=');
$nodes[] = $this->parser->getExpressionParser()->parseExpression();
break;
case Twig_Token::BLOCK_END_TYPE:
$end = true;
break;
default:
throw new Twig_Error_Syntax(sprintf('Invalid syntax in the partial tag. Line %s', $lineno), $stream->getCurrent()->getLine(), $stream->getFilename());
break;
}
}
return new ComponentNode(new Twig_Node($nodes), $paramNames, $token->getLine(), $this->getTag());
}
/**

View File

@ -167,11 +167,13 @@ class Extension extends Twig_Extension
/**
* Renders a component's default content.
* @param string $name Specifies the component name.
* @param array $parameters A optional list of parameters to pass to the component.
* @return string Returns the component default contents.
*/
public function componentFunction($name)
public function componentFunction($name, $parameters = [])
{
return $this->controller->renderComponent($name);
return $this->controller->renderComponent($name, $parameters);
}
/**

View File

@ -1,8 +1,8 @@
<?php namespace Cms\Twig;
use Twig_Node;
use Twig_Token;
use Twig_TokenParser;
use Twig_Node;
use Twig_Error_Syntax;
/**
@ -52,9 +52,8 @@ class PartialTokenParser extends Twig_TokenParser
$end = true;
break;
default :
default:
throw new Twig_Error_Syntax(sprintf('Invalid syntax in the partial tag. Line %s', $lineno), $stream->getCurrent()->getLine(), $stream->getFilename());
break;
}
}

View File

@ -42,7 +42,7 @@ trait PropertyContainer
}
/**
* Defines the properties used by this class.
* Defines the properties used by this class.
* This method should be used as an override in the extended class.
*/
public function defineProperties()