Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRUD v5 support #82

Merged
merged 5 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ _**Note:** this interface allows the admin to directly edit the language files s
> ### Security updates and breaking changes
> Please **[subscribe to the Backpack Newsletter](http://backpackforlaravel.com/newsletter)** so you can find out about any security updates, breaking changes or major features. We send an email every 1-2 months.

## Install in Backpack 4.1 (Laravel 6 or 7)
## Upgrading from 3.x to 4.x

- Flags are no longer supported on the Language CRUD, until version 3 admins could browse an image for the language flag, we now recommend developers to setup those images in advance, having them in a public folder like `public\flags\en.svg` `public\flags\ro.svg`.

## Install in Backpack 4.1 or 5.0 (Laravel 6, 7, 8 or 9)

### Step 1. Install via Composer

Expand Down Expand Up @@ -93,7 +97,7 @@ Or just try at **your-project-domain/admin/language/texts**

## Screenshots

See http://laravelbackpack.com
See https://backpackforlaravel.com/

## Change log

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
}
],
"require": {
"backpack/crud": "^4.1.0"
"backpack/crud": "^5.0"
},
"require-dev": {
"phpunit/phpunit" : "4.*",
"phpunit/phpunit" : "^9.0",
"scrutinizer/ocular": "~1.1"
},
"autoload": {
Expand Down
5 changes: 2 additions & 3 deletions src/app/Http/Controllers/LanguageCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function setupCreateOperation()
$this->crud->addField([
'name' => 'flag',
'label' => trans('backpack::langfilemanager.flag_image'),
'type' => 'browse',
'type' => backpack_pro() ? 'browse' : 'text',
]);
$this->crud->addField([
'name' => 'active',
Expand Down Expand Up @@ -97,8 +97,7 @@ public function store()
/**
* After delete remove also the language folder.
*
* @param int $id
*
* @param int $id
* @return string
*/
public function destroy($id)
Expand Down
44 changes: 26 additions & 18 deletions src/app/Services/LangFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public function setFile($file)

/**
* Get the content of a language file as an array sorted ascending.
* @return array|false
*
* @return array|false
*/
public function getFileContent()
{
Expand All @@ -47,8 +48,9 @@ public function getFileContent()

/**
* Rewrite the file with the modified texts.
* @param array $postArray the data received from the form
* @return int
*
* @param array $postArray the data received from the form
* @return int
*/
public function setFileContent($postArray)
{
Expand All @@ -65,7 +67,8 @@ public function setFileContent($postArray)
/**
* Get the language files that can be edited,
* to ignore a file add it in the config/admin file to language_ignore key.
* @return array
*
* @return array
*/
public function getlangFiles()
{
Expand Down Expand Up @@ -94,8 +97,9 @@ public function getlangFiles()

/**
* Check if all the fields were completed.
* @param array $postArray the array containing the data
* @return array
*
* @param array $postArray the array containing the data
* @return array
*/
public function testFields($postArray)
{
Expand All @@ -122,11 +126,12 @@ public function testFields($postArray)

/**
* Display the form that permits the editing.
* @param array $fileArray the array with all the texts
* @param array $parents all the ancestor keys of the current key
* @param string $parent the parent key of the current key
* @param int $level the current level
* @return void
*
* @param array $fileArray the array with all the texts
* @param array $parents all the ancestor keys of the current key
* @param string $parent the parent key of the current key
* @param int $level the current level
* @return void
*/
public function displayInputs($fileArray, $parents = [], $parent = '', $level = 0)
{
Expand Down Expand Up @@ -157,7 +162,8 @@ public function displayInputs($fileArray, $parents = [], $parent = '', $level =

/**
* Create the array that will be saved in the file.
* @param array $postArray The array to be transformed
*
* @param array $postArray The array to be transformed
* @return array
*/
private function prepareContent($postArray)
Expand Down Expand Up @@ -194,8 +200,9 @@ function ($item1, $item2) {

/**
* Add filters to the values inserted by the user.
* @param string $str the string to be sanitized
* @return string
*
* @param string $str the string to be sanitized
* @return string
*/
private function sanitize($str)
{
Expand All @@ -204,10 +211,11 @@ private function sanitize($str)

/**
* Set a value in a multidimensional array when knowing the keys.
* @param array $data the array that will be modified
* @param array $keys the keys (path)
* @param string $value the value to be added
* @return array
*
* @param array $data the array that will be modified
* @param array $keys the keys (path)
* @param string $value the value to be added
* @return array
*/
private function setArrayValue(&$data, $keys, $value)
{
Expand Down