Skip to content

Commit

Permalink
Merge branch '4.1' into 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Guy Marriott authored and Guy Marriott committed Sep 3, 2019
2 parents e2a5788 + 37b3db1 commit 6c70024
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 33 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,10 @@ globally in your command line.
**Note:** If adding or modifying colours, spacing, font sizes etc. please try
and use an appropriate variable from the silverstripe/admin module if available.

## Advanced setup
## Integration with other modules

* [Advanced setup](docs/en/advanced_setup.md)
* [Multiple languages with tractorcow/silverstripe-fluent](docs/en/advanced_setup.md)
* [Search through silverstripe/fulltextsearch](docs/en/searching-blocks.md)

## Upgrading

Expand Down
1 change: 1 addition & 0 deletions _config/graphql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ SilverStripe\GraphQL\Manager:
nestedQueries:
Elements:
resolver: DNADesign\Elemental\GraphQL\ElementsResolver
paginate: false
operations:
readOne:
resolver: DNADesign\Elemental\GraphQL\ReadOneAreaResolver
Expand Down
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions client/src/components/ElementActions/PublishAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ const performSaveForElementWithFormData = (id, formData, securityId) => {
.data
.readOneElementalArea
.Elements
.edges
.find((elementData) => elementData.node.ID === id);
return newElementData && newElementData.node.Version;
.find((elementData) => elementData.ID === id);
return newElementData && newElementData.Version;
});
};

Expand Down
21 changes: 7 additions & 14 deletions client/src/state/editor/readBlocksForAreaQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,12 @@ query ReadBlocksForArea($id:ID!) {
Mode: DRAFT
}){
Elements {
pageInfo {
totalCount
}
edges {
node {
ID
Title
BlockSchema
IsLiveVersion
IsPublished
Version
}
}
ID
Title
BlockSchema
IsLiveVersion
IsPublished
Version
}
}
}
Expand All @@ -48,7 +41,7 @@ const config = {
let blocks = null;
if (readOneElementalArea) {
// Remove the GraphQL pagination keys
blocks = readOneElementalArea.Elements.edges.map((element) => element.node);
blocks = readOneElementalArea.Elements;
}

const errors = error && error.graphQLErrors &&
Expand Down
22 changes: 11 additions & 11 deletions client/src/state/editor/sortBlockMutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ const config = {
// Query returns a deeply nested object. Explicit reconstruction via spreads is too verbose.
// This is an alternative, relatively efficient way to deep clone
const newData = JSON.parse(JSON.stringify(cachedData));
let { edges } = newData.readOneElementalArea.Elements;
let blocks = newData.readOneElementalArea.Elements;

// Find the block we reordered
const movedBlockIndex = edges.findIndex(edge => edge.node.ID === blockId);
const movedBlockIndex = blocks.findIndex(block => block.ID === blockId);
// Keep it
const movedBlock = edges[movedBlockIndex];
const movedBlock = blocks[movedBlockIndex];
// Update the moved block with the new details returned in the GraphQL response
Object.entries(updatedElementData).forEach(([key, value]) => {
// Skip the type name as this is always returned but should never change
Expand All @@ -53,22 +53,22 @@ const config = {
movedBlock[key] = value;
});
// Remove the moved block
edges.splice(movedBlockIndex, 1);
blocks.splice(movedBlockIndex, 1);
// If the target is 0, it's added to the start
if (!afterBlockId) {
edges.unshift(movedBlock);
blocks.unshift(movedBlock);
} else {
// Else, find the block we inserted after
const targetBlockIndex = edges.findIndex(edge => edge.node.ID === afterBlockId);
const targetBlockIndex = blocks.findIndex(block => block.ID === afterBlockId);
// Add it back after the target
const end = edges.slice(targetBlockIndex + 1);
edges = edges.slice(0, targetBlockIndex + 1);
edges.push(movedBlock);
edges = edges.concat(end);
const end = blocks.slice(targetBlockIndex + 1);
blocks = blocks.slice(0, targetBlockIndex + 1);
blocks.push(movedBlock);
blocks = blocks.concat(end);
}

// Add it back to the full result
newData.readOneElementalArea.Elements.edges = edges;
newData.readOneElementalArea.Elements = blocks;
store.writeQuery({ query: readBlocksQuery, data: newData, variables });
},
});
Expand Down
32 changes: 32 additions & 0 deletions docs/en/searching-blocks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Searching Blocks

## Overview

Content created through SilverStripe can be searched in various ways.
A popular option is the [silverstripe/fulltextsearch](https://github.com/silverstripe/silverstripe-fulltextsearch)
module, which integrates with search services such as Solr.

## Usage

When you install the fulltextsearch module, it will auto-discover
an index provided by elemental:
`DNADesign\Elemental\Search\ElementalSolrIndex`.

It works based on a new `getElementsForSearch` method added to your `Page` class
through the `DNADesign\Elemental\Extensions\ElementalPageExtension`.
This method renders out the full content of all elements,
strips out the HTML, and indexes it as one field.

## Configuration

In many cases, you'll already have configured your own search index.
Since the `ElementalSolrIndex` is auto-discovered, it duplicates
search indexing effort even when it is unused.

You can disable it via YAML config in favour of your own index definition:

```yml
SilverStripe\FullTextSearch\Search\FullTextSearch:
indexes:
- MyCustomIndex
```
13 changes: 12 additions & 1 deletion src/Forms/EditFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace DNADesign\Elemental\Forms;

use SilverStripe\Control\RequestHandler;
use SilverStripe\Core\Config\Configurable;
use SilverStripe\Forms\DefaultFormFactory;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\FormField;
Expand All @@ -11,6 +12,16 @@

class EditFormFactory extends DefaultFormFactory
{
use Configurable;

/**
* This will be set the number of rows in HTML field
*
* @config
* @var integer
*/
private static $html_field_rows = 7;

/**
* @var string
*/
Expand Down Expand Up @@ -39,7 +50,7 @@ protected function getFormFields(RequestHandler $controller = null, $name, $cont
/** @var HTMLEditorField|null $editorField */
$editorField = $fields->fieldByName('Root.Main.HTML');
if ($editorField) {
$editorField->setRows(7);
$editorField->setRows($this->config()->get('html_field_rows'));
}

return $fields;
Expand Down
4 changes: 3 additions & 1 deletion src/Models/BaseElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,9 @@ public function CMSEditLink($directLink = false)
$page = $this->getPage();

if (!$page) {
return null;
$link = null;
$this->extend('updateCMSEditLink', $link);
return $link;
}

if (!$page instanceof SiteTree && method_exists($page, 'CMSEditLink')) {
Expand Down

0 comments on commit 6c70024

Please sign in to comment.