Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
tmgmt_smartling
Commits
c021693d
Commit
c021693d
authored
Aug 11, 2020
by
Loparev
Browse files
Set batch operation per job + job item
parent
e4e36b4f
Changes
4
Hide whitespace changes
Inline
Side-by-side
config/install/system.action.tmgmt_smartling_download_by_job_items_job_action.yml
View file @
c021693d
...
...
@@ -4,7 +4,7 @@ dependencies:
module
:
-
tmgmt
id
:
tmgmt_smartling_download_by_job_items_job_action
label
:
'
Download
Translation
by
TMGMT
J
ob
I
tems'
label
:
'
Download
Translation
(
by
j
ob
i
tems
)
'
type
:
tmgmt_job
plugin
:
tmgmt_smartling_download_by_job_items_job_action
configuration
:
{
}
config/schema/tmgmt_smartling.schema.yml
View file @
c021693d
...
...
@@ -81,4 +81,4 @@ action.configuration.tmgmt_smartling_send_context_action:
action.configuration.tmgmt_smartling_download_by_job_items_job_action
:
type
:
action_configuration_default
label
:
'
Download
Translation
by
TMGMT
J
ob
I
tems'
label
:
'
Download
Translation
(
by
j
ob
i
tems
)
'
src/Form/DownloadByJobItemsTmgmtActionApproveForm.php
View file @
c021693d
...
...
@@ -3,6 +3,9 @@
namespace
Drupal\tmgmt_smartling\Form
;
use
Drupal\Component\Render\FormattableMarkup
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\tmgmt\Entity\Job
;
use
Drupal\tmgmt\Entity\JobItem
;
use
Drupal\tmgmt_extension_suit
\
ExtendedTranslatorPluginInterface
;
use
Drupal\tmgmt_extension_suit
\
Form\BaseTmgmtActionApproveForm
;
...
...
@@ -11,6 +14,13 @@ use Drupal\tmgmt_extension_suit\Form\BaseTmgmtActionApproveForm;
*/
class
DownloadByJobItemsTmgmtActionApproveForm
extends
BaseTmgmtActionApproveForm
{
/**
* Temp storage name we are saving entity_ids to.
*
* @var string
*/
protected
$tempStorageName
=
'tmgmt_smartling_tmgmt_job_operations_download_by_job_items'
;
/**
* {@inheritdoc}
*/
...
...
@@ -22,7 +32,7 @@ class DownloadByJobItemsTmgmtActionApproveForm extends BaseTmgmtActionApproveFor
* {@inheritdoc}
*/
public
function
getConfirmText
()
{
return
$this
->
t
(
'Download Translation by
TMGMT J
ob
I
tems'
);
return
$this
->
t
(
'Download Translation
(
by
j
ob
i
tems
)
'
);
}
/**
...
...
@@ -39,17 +49,87 @@ class DownloadByJobItemsTmgmtActionApproveForm extends BaseTmgmtActionApproveFor
return
$this
->
t
(
'Downloading can take some time, do not close the browser'
);
}
/**
* {@inheritdoc}
*/
public
function
submitForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
$current_user_id
=
$this
->
currentUser
()
->
id
();
$temp_storage_name
=
$this
->
getTempStorageName
();
// Clear out the accounts from the temp store.
$this
->
tempStoreFactory
->
get
(
$temp_storage_name
)
->
delete
(
$current_user_id
);
if
(
!
$form_state
->
getValue
(
'confirm'
))
{
return
;
}
$operations
=
[];
foreach
(
$this
->
entityIds
as
$id
=>
$entity_type
)
{
$job
=
Job
::
load
(
$id
);
if
(
empty
(
$job
))
{
continue
;
}
foreach
(
$job
->
getItems
()
as
$item
)
{
$batch_item_data
=
[
'tjid'
=>
$job
->
id
(),
'tjiid'
=>
$item
->
id
()
];
$operations
[]
=
[
[
get_class
(
$this
),
'processBatch'
],
[
$batch_item_data
],
];
}
}
if
(
!
empty
(
$operations
))
{
$batch
=
[
'title'
=>
$this
->
getConfirmText
(),
'operations'
=>
$operations
,
'finished'
=>
[
get_class
(
$this
),
'finishBatch'
],
];
batch_set
(
$batch
);
}
else
{
$form_state
->
setRedirect
(
'system.admin_content'
);
}
}
/**
* {@inheritdoc}
*/
public
static
function
processBatch
(
array
$data
,
array
&
$context
)
{
$job
=
parent
::
processBatch
(
$data
,
$context
);
if
(
!
isset
(
$context
[
'results'
][
'errors'
]))
{
$context
[
'results'
][
'errors'
]
=
[];
$context
[
'results'
][
'count'
]
=
0
;
}
if
(
!
empty
(
$job
)
&&
$translator
=
$job
->
getTranslator
())
{
$job
=
Job
::
load
(
$data
[
"tjid"
]);
$job_item
=
JobItem
::
load
(
$data
[
"tjiid"
]);
if
(
!
$job
)
{
$context
[
'results'
][
'errors'
][]
=
t
(
'TMGMT Job @id not found'
,
[
'@id'
=>
$data
[
"tjid"
]
]);
}
if
(
!
$job_item
)
{
$context
[
'results'
][
'errors'
][]
=
t
(
'TMGMT Job Item @id not found'
,
[
'@id'
=>
$data
[
"tjiid"
]
]);
}
if
(
$translator
=
$job
->
getTranslator
())
{
$plugin
=
$translator
->
getPlugin
();
if
(
$plugin
instanceof
ExtendedTranslatorPluginInterface
&&
$plugin
->
downloadTranslation
(
$job
))
{
if
(
$plugin
instanceof
ExtendedTranslatorPluginInterface
&&
$plugin
->
downloadTranslation
(
$job
,
$job_item
)
)
{
$context
[
'results'
][
'count'
]
++
;
}
else
{
...
...
@@ -66,7 +146,7 @@ class DownloadByJobItemsTmgmtActionApproveForm extends BaseTmgmtActionApproveFor
}
else
{
$context
[
'message'
]
=
new
FormattableMarkup
(
'Skipped %name.'
,
[
'%name'
=>
$
data
[
'entity_type'
]
,
'%name'
=>
$
job
->
label
()
,
]);
}
}
...
...
src/Plugin/Action/DowloadByJobItemsJobAction.php
View file @
c021693d
...
...
@@ -9,7 +9,7 @@ use Drupal\tmgmt_extension_suit\Plugin\Action\BaseJobAction;
*
* @Action(
* id = "tmgmt_smartling_download_by_job_items_job_action",
* label = @Translation("Download Translation by
TMGMT J
ob
I
tems"),
* label = @Translation("Download Translation
(
by
j
ob
i
tems
)
"),
* type = "tmgmt_job",
* confirm_form_route_name = "tmgmt_smartling.download_by_job_items_approve_action"
* )
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment