Skip to content

Commit

Permalink
Merge branch '4' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored Jan 17, 2022
2 parents 770d1cb + a16873d commit 356ad3d
Show file tree
Hide file tree
Showing 35 changed files with 1,799 additions and 1,348 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,19 @@ The Solr search results may add in emphasis tags or other formatting around matc
to allow unescaped HTML in your search results template. You should use the `$Excerpt` property (see
`SolrIndex::search` for more) to display the relevant search matches.

### Disabling CMS content search

When installing this module, the page model admin search will look for a term in the entire content of each elemental pages.
This is done by rendering each page, which can be resource hungry and make the search timeout.

You can disable this with YAML configuration:

```yaml
# File: mysite/_config/elements.yml
DNADesign\Elemental\Controllers\ElementSiteTreeFilterSearch:
search_for_term_in_content: false
```

### Usage of GridField

This module used to use GridField to create and update Elements in the CMS. This has now been largely succeeded by a JavaScript interface via React. However elements that are marked as being incompatible with in-line editing will still use the GridField method.
Expand Down
2 changes: 1 addition & 1 deletion client/src/bundles/bundle.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
require('legacy/ElementEditor/entwine.js');
require('legacy/ElementEditor/entwine');
require('boot');
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^7.1",
"php": "^7.3 || ^8.0",
"silverstripe/framework": "^4.10@dev",
"silverstripe/cms": "^4.7@dev",
"silverstripe/admin": "^1.7@dev",
"silverstripe/versioned": "^1.7@dev",
Expand All @@ -26,7 +27,7 @@
"silverstripe/vendor-plugin": "^1"
},
"require-dev": {
"silverstripe/recipe-testing": "1.x-dev"
"silverstripe/recipe-testing": "^2"
},
"suggest": {
"silverstripe/elemental-blocks": "Adds a set of common SilverStripe content block types",
Expand Down
2 changes: 1 addition & 1 deletion docs/en/advanced_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ TractorCow\Fluent\Model\Locale:
In the case your fixture needs to contain data for only a single locale you can specify your desired locale in your unit test like this:
```php
protected function setUp()
protected function setUp(): void
{
// Set locale for fixture creation
FluentState::singleton()->withState(function (FluentState $state) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"redux-form": "^6.8.0"
},
"devDependencies": {
"@silverstripe/eslint-config": "^0.0.5",
"@silverstripe/eslint-config": "^0.0.6",
"@silverstripe/webpack-config": "^1.5.0",
"babel-jest": "^23.6.0",
"enzyme": "^3.6.0",
Expand Down
9 changes: 5 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true">
<testsuite name="Default">
<directory>tests</directory>
</testsuite>

<testsuites>
<testsuite name="Default">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/</directory>
Expand Down
7 changes: 5 additions & 2 deletions src/Controllers/ElementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,20 @@ public function getElement()
public function forTemplate()
{
$defaultStyles = $this->config()->get('default_styles');
$this->extend('updateForTemplateDefaultStyles', $defaultStyles);

if ($this->config()->get('include_default_styles') && !empty($defaultStyles)) {
foreach ($defaultStyles as $stylePath) {
Requirements::css($stylePath);
}
}

$template = $this->element->config()->get('controller_template');
$template = 'DNADesign\\Elemental\\' . $this->element->config()->get('controller_template');
$this->extend('updateForTemplateTemplate', $template);

return $this->renderWith([
'type' => 'Layout',
'DNADesign\\Elemental\\'.$template
$template
]);
}

Expand Down
12 changes: 9 additions & 3 deletions src/Controllers/ElementSiteTreeFilterSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@
use DNADesign\Elemental\Extensions\ElementalPageExtension;
use SilverStripe\CMS\Controllers\CMSSiteTreeFilter_Search;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Config\Configurable;
use SilverStripe\Core\Convert;
use SilverStripe\Forms\DateField;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataList;
use SilverStripe\View\SSViewer;

class ElementSiteTreeFilterSearch extends CMSSiteTreeFilter_Search
{
use Configurable;

/**
* @var boolean
*/
private static $search_for_term_in_content = true;

/**
* @var array
*/
Expand All @@ -29,7 +35,7 @@ class ElementSiteTreeFilterSearch extends CMSSiteTreeFilter_Search
protected function applyDefaultFilters($query)
{
// If not filtering by a Term then skip this altogether
if (empty($this->params['Term'])) {
if (empty($this->params['Term']) || $this->config()->get('search_for_term_in_content') === false) {
return parent::applyDefaultFilters($query);
}

Expand Down
2 changes: 0 additions & 2 deletions src/Forms/EditFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
use SilverStripe\Core\Config\Configurable;
use SilverStripe\Forms\DefaultFormFactory;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\FormField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Forms\HTMLEditor\TinyMCEConfig;

class EditFormFactory extends DefaultFormFactory
{
Expand Down
7 changes: 0 additions & 7 deletions src/Forms/ElementalAreaConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,8 @@
namespace DNADesign\Elemental\Forms;

use SilverStripe\Forms\GridField\GridFieldConfig;
use SilverStripe\Forms\GridField\GridFieldButtonRow;
use SilverStripe\Forms\GridField\GridFieldToolbarHeader;
use SilverStripe\Forms\GridField\GridFieldFilterHeader;
use SilverStripe\Forms\GridField\GridFieldDataColumns;
use SilverStripe\Forms\GridField\GridFieldEditButton;
use SilverStripe\Forms\GridField\GridFieldDeleteAction;
use SilverStripe\Forms\GridField\GridFieldDetailForm;
use SilverStripe\Versioned\VersionedGridFieldState\VersionedGridFieldState;
use Symbiote\GridFieldExtensions\GridFieldOrderableRows;

class ElementalAreaConfig extends GridFieldConfig
{
Expand Down
4 changes: 0 additions & 4 deletions src/Forms/ElementalAreaField.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

namespace DNADesign\Elemental\Forms;

use BlocksPage;
use DNADesign\Elemental\Controllers\ElementalAreaController;
use DNADesign\Elemental\Models\BaseElement;
use DNADesign\Elemental\Models\ElementalArea;
use DNADesign\Elemental\Services\ElementTabProvider;
use SilverStripe\Control\Controller;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Forms\CompositeField;
use SilverStripe\Forms\FieldGroup;
Expand Down Expand Up @@ -221,7 +218,6 @@ public function setSubmittedValue($value, $data = null)

public function saveInto(DataObjectInterface $dataObject)
{
/** @var BlocksPage $dataObject */
parent::saveInto($dataObject);

$elementData = $this->Value();
Expand Down
37 changes: 25 additions & 12 deletions src/Models/BaseElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
use SilverStripe\Forms\TextField;
use SilverStripe\GraphQL\Scaffolding\StaticSchema;
use SilverStripe\GraphQL\Schema\Exception\SchemaBuilderException;
use SilverStripe\GraphQL\Schema\Schema;
use SilverStripe\GraphQL\Schema\SchemaBuilder;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\FieldType\DBBoolean;
use SilverStripe\ORM\FieldType\DBField;
Expand All @@ -33,7 +31,6 @@
use SilverStripe\View\ArrayData;
use SilverStripe\View\Parsers\URLSegmentFilter;
use SilverStripe\View\Requirements;
use RuntimeException;
use SilverStripe\Core\Config\Config;

/**
Expand All @@ -48,6 +45,8 @@
* @property int $ParentID
*
* @method ElementalArea Parent()
*
* @mixin Versioned
*/
class BaseElement extends DataObject
{
Expand Down Expand Up @@ -92,6 +91,10 @@ class BaseElement extends DataObject
'canDelete' => DBBoolean::class,
];

private static $indexes = [
'Sort' => true,
];

private static $versioned_gridfield_extensions = true;

private static $table_name = 'Element';
Expand Down Expand Up @@ -291,17 +294,25 @@ public function onBeforeWrite()
{
parent::onBeforeWrite();

if (!$this->Sort) {
if ($this->hasExtension(Versioned::class)) {
$records = Versioned::get_by_stage(BaseElement::class, Versioned::DRAFT);
} else {
$records = BaseElement::get();
}
// If a Sort has already been set, then we can exit early
if ($this->Sort) {
return;
}

$records = $records->filter('ParentID', $this->ParentID);
// If no ParentID is currently set for the Element, then we don't want to define an initial Sort yet
if (!$this->ParentID) {
return;
}

$this->Sort = $records->max('Sort') + 1;
if ($this->hasExtension(Versioned::class)) {
$records = Versioned::get_by_stage(BaseElement::class, Versioned::DRAFT);
} else {
$records = BaseElement::get();
}

$records = $records->filter('ParentID', $this->ParentID);

$this->Sort = $records->max('Sort') + 1;
}

public function getCMSFields()
Expand Down Expand Up @@ -398,7 +409,9 @@ public function getCMSFields()
*/
public function getType()
{
return _t(__CLASS__ . '.BlockType', 'Block');
$default = $this->i18n_singular_name() ?: 'Block';

return _t(__CLASS__ . '.BlockType', $default);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Models/ElementContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Forms\HTMLEditor\TinyMCEConfig;
use SilverStripe\ORM\FieldType\DBField;

/**
* @property string $HTML
*/
class ElementContent extends BaseElement
{
private static $icon = 'font-icon-block-content';
Expand Down
3 changes: 2 additions & 1 deletion src/Models/ElementalArea.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\ORM\FieldType\DBHTMLText;
Expand All @@ -21,6 +20,8 @@
* @package DNADesign\Elemental\Models
*
* @property string $OwnerClassName
*
* @mixin Versioned
*/
class ElementalArea extends DataObject
{
Expand Down
1 change: 0 additions & 1 deletion src/Services/ElementTypeRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Injector\Injectable;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\GraphQL\Scaffolding\StaticSchema;
use SilverStripe\GraphQL\Schema\Exception\SchemaBuilderException;

class ElementTypeRegistry
Expand Down
16 changes: 12 additions & 4 deletions tests/BaseElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function testLink()
{
$element = $this->objFromFixture(ElementContent::class, 'content1');

$this->assertContains($element->getPage()->Link(), $element->Link());
$this->assertStringContainsString($element->getPage()->Link(), $element->Link());
}

public function testGetEditLink()
Expand All @@ -118,14 +118,14 @@ public function testGetEditLink()
$element = $this->objFromFixture(ElementContent::class, 'content1');
$editLink = $element->getEditLink();

$this->assertContains('http://example.com', $editLink, 'Link should be absolute');
$this->assertContains('pages/edit', $editLink, 'Link should contain reference to the page');
$this->assertStringContainsString('http://example.com', $editLink, 'Link should be absolute');
$this->assertStringContainsString('pages/edit', $editLink, 'Link should contain reference to the page');
}

public function testGetIcon()
{
$element = new ElementContent();
$this->assertContains('class="font-icon-block-content"', $element->getIcon());
$this->assertStringContainsString('class="font-icon-block-content"', $element->getIcon());

Config::modify()->set(ElementContent::class, 'icon', '');
$this->assertEmpty($element->getIcon());
Expand Down Expand Up @@ -228,4 +228,12 @@ public function testOnBeforeWrite()
$element3->write();
$this->assertEquals($baselineSort + 2, $element3->Sort, 'Sort order should be higher than the max');
}

public function testOnBeforeWriteNoParent()
{
$element1 = new ElementContent();
$element1->write();

$this->assertEquals(0, (int) $element1->Sort);
}
}
Loading

0 comments on commit 356ad3d

Please sign in to comment.