Skip to content

Commit

Permalink
Rename message to body
Browse files Browse the repository at this point in the history
  • Loading branch information
vinkla committed Nov 2, 2023
1 parent deceea5 commit a249453
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 56 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,8 @@ Group::make('Hero')
```php
use Extended\ACF\Fields\Message;

Message::make('Message')
->message('George. One point twenty-one gigawatts.')
Message::make('Heading')
->text('George. One point twenty-one gigawatts.')
->escapeHtml(),
```

Expand Down Expand Up @@ -1009,6 +1009,13 @@ The `mediaUpload` method has been renamed to `disableMediaUpload`.
+WYSIWYGEditor::make('Narrative')->disableMediaUpload()
```

The `message` method has been renamed to `text`.

```diff
-Message::make('Heading')->message('Text')
+Message::make('Heading')->body('Text')
```

The `MimeTypes` trait has been renamed to `FileTypes`.

```diff
Expand Down Expand Up @@ -1044,6 +1051,12 @@ The `SubFields` trait has been renamed to `Fields`.
+use Extended\ACF\Fields\Settings\Fields;
```

The `Message` trait has been removed.

```diff
-use Extended\ACF\Fields\Settings\Message;
```

Changelog: [`13.0.0...14.0.0`](https://github.com/vinkla/extended-acf/compare/13.0.0...14.0.0)

### 13
Expand Down
21 changes: 19 additions & 2 deletions src/Fields/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,34 @@
namespace Extended\ACF\Fields;

use Extended\ACF\Fields\Settings\ConditionalLogic;
use Extended\ACF\Fields\Settings\Message as MessageAttribute;
use Extended\ACF\Fields\Settings\NewLines;

class Message extends Field
{
use ConditionalLogic;
use MessageAttribute;
use NewLines;

protected string|null $type = 'message';

public function body(string $text): static
{
// Replace emphasis formatting: *text* or _text_ => <em>text</em>
$text = preg_replace('/\*\*(.*?)\*\*|__(.*?)__/', '<strong>$1$2</strong>', $text);

// Replace strong formatting: **text** or __text__ => <strong>text</strong>
$text = preg_replace('/\*(.*?)\*|_(.*?)_/', '<em>$1$2</em>', $text);

// Replace <code> formatting: `code` => <code>code</code>
$text = preg_replace('/\`(.*?)\`/', '<code>$1</code>', $text);

// Replace link formatting: [text](url) => <a href="url">text</a>
$text = preg_replace('/\[(.*?)\]\((.*?)\)/', '<a href="$2">$1</a>', $text);

$this->settings['message'] = $text;

return $this;
}

public function escapeHtml(): static
{
$this->settings['esc_html'] = true;
Expand Down
24 changes: 0 additions & 24 deletions src/Fields/Settings/Message.php

This file was deleted.

8 changes: 7 additions & 1 deletion src/Fields/TrueFalse.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ class TrueFalse extends Field
use ConditionalLogic;
use DefaultValue;
use Instructions;
use Message;
use Required;
use Wrapper;

protected string|null $type = 'true_false';

public function message(string $text): static
{
$this->settings['message'] = $text;

return $this;
}

public function stylized(string $on = null, string $off = null): static
{
$this->settings['ui'] = true;
Expand Down
8 changes: 6 additions & 2 deletions tests/Fields/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,22 @@

use Extended\ACF\Fields\Message;
use Extended\ACF\Tests\Fields\Settings\ConditionalLogic;
use Extended\ACF\Tests\Fields\Settings\Message as MessageAttribute;
use Extended\ACF\Tests\Fields\Settings\NewLines;

class MessageTest extends FieldTestCase
{
use ConditionalLogic;
use MessageAttribute;
use NewLines;

public string $field = Message::class;
public string $type = 'message';

public function testBody()
{
$field = Message::make('Body')->body('text **strong** *italic* __strong__ _italic_ `code` [link](https://advancedcustomfields.com/)')->get();
$this->assertSame('text <strong>strong</strong> <em>italic</em> <strong>strong</strong> <em>italic</em> <code>code</code> <a href="https://advancedcustomfields.com/">link</a>', $field['message']);
}

public function testEscapeHtml()
{
$field = Message::make('Escape HTML')->escapeHtml()->get();
Expand Down
23 changes: 0 additions & 23 deletions tests/Fields/Settings/Message.php

This file was deleted.

8 changes: 6 additions & 2 deletions tests/Fields/TrueFalseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Extended\ACF\Tests\Fields\Settings\ConditionalLogic;
use Extended\ACF\Tests\Fields\Settings\DefaultValue;
use Extended\ACF\Tests\Fields\Settings\Instructions;
use Extended\ACF\Tests\Fields\Settings\Message;
use Extended\ACF\Tests\Fields\Settings\Required;
use Extended\ACF\Tests\Fields\Settings\Wrapper;

Expand All @@ -26,13 +25,18 @@ class TrueFalseTest extends FieldTestCase
use ConditionalLogic;
use DefaultValue;
use Instructions;
use Message;
use Required;
use Wrapper;

public string $field = TrueFalse::class;
public string $type = 'true_false';

public function testMessage()
{
$field = TrueFalse::make('Content')->message('Adam Whatan')->get();
$this->assertSame('Adam Whatan', $field['message']);
}

public function testStylized()
{
$field = TrueFalse::make('Stylized')->stylized(off: 'Wax off')->get();
Expand Down

0 comments on commit a249453

Please sign in to comment.